@servicetitan/journey 1.0.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 (136) hide show
  1. package/README.md +7 -0
  2. package/dist/__mocks__/test-runtime.d.ts +16 -0
  3. package/dist/__mocks__/test-runtime.d.ts.map +1 -0
  4. package/dist/__tests__/ambient.test.d.ts +2 -0
  5. package/dist/__tests__/ambient.test.d.ts.map +1 -0
  6. package/dist/__tests__/axios.test.d.ts +2 -0
  7. package/dist/__tests__/axios.test.d.ts.map +1 -0
  8. package/dist/__tests__/config.test.d.ts +2 -0
  9. package/dist/__tests__/config.test.d.ts.map +1 -0
  10. package/dist/__tests__/context.test.d.ts +2 -0
  11. package/dist/__tests__/context.test.d.ts.map +1 -0
  12. package/dist/__tests__/datadog.test.d.ts +2 -0
  13. package/dist/__tests__/datadog.test.d.ts.map +1 -0
  14. package/dist/__tests__/define-journey.test.d.ts +2 -0
  15. package/dist/__tests__/define-journey.test.d.ts.map +1 -0
  16. package/dist/__tests__/expose-app-journey.test.d.ts +2 -0
  17. package/dist/__tests__/expose-app-journey.test.d.ts.map +1 -0
  18. package/dist/__tests__/fetch.test.d.ts +2 -0
  19. package/dist/__tests__/fetch.test.d.ts.map +1 -0
  20. package/dist/__tests__/jquery.test.d.ts +2 -0
  21. package/dist/__tests__/jquery.test.d.ts.map +1 -0
  22. package/dist/__tests__/registry.test.d.ts +2 -0
  23. package/dist/__tests__/registry.test.d.ts.map +1 -0
  24. package/dist/__tests__/request-key.test.d.ts +2 -0
  25. package/dist/__tests__/request-key.test.d.ts.map +1 -0
  26. package/dist/__tests__/requests.test.d.ts +2 -0
  27. package/dist/__tests__/requests.test.d.ts.map +1 -0
  28. package/dist/__tests__/runtime.test.d.ts +2 -0
  29. package/dist/__tests__/runtime.test.d.ts.map +1 -0
  30. package/dist/__tests__/scope.test.d.ts +2 -0
  31. package/dist/__tests__/scope.test.d.ts.map +1 -0
  32. package/dist/__tests__/sinks.test.d.ts +2 -0
  33. package/dist/__tests__/sinks.test.d.ts.map +1 -0
  34. package/dist/__tests__/step.test.d.ts +2 -0
  35. package/dist/__tests__/step.test.d.ts.map +1 -0
  36. package/dist/__tests__/timeouts.test.d.ts +2 -0
  37. package/dist/__tests__/timeouts.test.d.ts.map +1 -0
  38. package/dist/config.d.ts +42 -0
  39. package/dist/config.d.ts.map +1 -0
  40. package/dist/config.js +46 -0
  41. package/dist/config.js.map +1 -0
  42. package/dist/core/index.d.ts +6 -0
  43. package/dist/core/index.d.ts.map +1 -0
  44. package/dist/core/index.js +5 -0
  45. package/dist/core/index.js.map +1 -0
  46. package/dist/core/registry.d.ts +50 -0
  47. package/dist/core/registry.d.ts.map +1 -0
  48. package/dist/core/registry.js +102 -0
  49. package/dist/core/registry.js.map +1 -0
  50. package/dist/core/runtime.d.ts +51 -0
  51. package/dist/core/runtime.d.ts.map +1 -0
  52. package/dist/core/runtime.js +401 -0
  53. package/dist/core/runtime.js.map +1 -0
  54. package/dist/core/step-tag.d.ts +16 -0
  55. package/dist/core/step-tag.d.ts.map +1 -0
  56. package/dist/core/step-tag.js +35 -0
  57. package/dist/core/step-tag.js.map +1 -0
  58. package/dist/core/types.d.ts +143 -0
  59. package/dist/core/types.d.ts.map +1 -0
  60. package/dist/core/types.js +3 -0
  61. package/dist/core/types.js.map +1 -0
  62. package/dist/endpoint-policy.d.ts +29 -0
  63. package/dist/endpoint-policy.d.ts.map +1 -0
  64. package/dist/endpoint-policy.js +39 -0
  65. package/dist/endpoint-policy.js.map +1 -0
  66. package/dist/index.d.ts +15 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +19 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/integrations/axios.d.ts +23 -0
  71. package/dist/integrations/axios.d.ts.map +1 -0
  72. package/dist/integrations/axios.js +51 -0
  73. package/dist/integrations/axios.js.map +1 -0
  74. package/dist/integrations/fetch.d.ts +21 -0
  75. package/dist/integrations/fetch.d.ts.map +1 -0
  76. package/dist/integrations/fetch.js +63 -0
  77. package/dist/integrations/fetch.js.map +1 -0
  78. package/dist/integrations/jquery/index.d.ts +22 -0
  79. package/dist/integrations/jquery/index.d.ts.map +1 -0
  80. package/dist/integrations/jquery/index.js +27 -0
  81. package/dist/integrations/jquery/index.js.map +1 -0
  82. package/dist/integrations/jquery/instrument.d.ts +18 -0
  83. package/dist/integrations/jquery/instrument.d.ts.map +1 -0
  84. package/dist/integrations/jquery/instrument.js +44 -0
  85. package/dist/integrations/jquery/instrument.js.map +1 -0
  86. package/dist/integrations/react/context.d.ts +6 -0
  87. package/dist/integrations/react/context.d.ts.map +1 -0
  88. package/dist/integrations/react/context.js +14 -0
  89. package/dist/integrations/react/context.js.map +1 -0
  90. package/dist/integrations/react/scope.d.ts +13 -0
  91. package/dist/integrations/react/scope.d.ts.map +1 -0
  92. package/dist/integrations/react/scope.js +27 -0
  93. package/dist/integrations/react/scope.js.map +1 -0
  94. package/dist/integrations/request-key.d.ts +17 -0
  95. package/dist/integrations/request-key.d.ts.map +1 -0
  96. package/dist/integrations/request-key.js +39 -0
  97. package/dist/integrations/request-key.js.map +1 -0
  98. package/dist/sinks/datadog.d.ts +6 -0
  99. package/dist/sinks/datadog.d.ts.map +1 -0
  100. package/dist/sinks/datadog.js +64 -0
  101. package/dist/sinks/datadog.js.map +1 -0
  102. package/package.json +44 -0
  103. package/src/__mocks__/test-runtime.ts +37 -0
  104. package/src/__tests__/ambient.test.ts +101 -0
  105. package/src/__tests__/axios.test.ts +365 -0
  106. package/src/__tests__/config.test.ts +261 -0
  107. package/src/__tests__/context.test.tsx +84 -0
  108. package/src/__tests__/datadog.test.ts +160 -0
  109. package/src/__tests__/define-journey.test.ts +176 -0
  110. package/src/__tests__/expose-app-journey.test.ts +149 -0
  111. package/src/__tests__/fetch.test.ts +264 -0
  112. package/src/__tests__/jquery.test.ts +327 -0
  113. package/src/__tests__/registry.test.ts +265 -0
  114. package/src/__tests__/request-key.test.ts +81 -0
  115. package/src/__tests__/requests.test.ts +337 -0
  116. package/src/__tests__/runtime.test.ts +273 -0
  117. package/src/__tests__/scope.test.tsx +128 -0
  118. package/src/__tests__/sinks.test.ts +99 -0
  119. package/src/__tests__/step.test.ts +305 -0
  120. package/src/__tests__/timeouts.test.ts +226 -0
  121. package/src/config.ts +87 -0
  122. package/src/core/index.ts +39 -0
  123. package/src/core/registry.ts +162 -0
  124. package/src/core/runtime.ts +489 -0
  125. package/src/core/step-tag.ts +24 -0
  126. package/src/core/types.ts +160 -0
  127. package/src/endpoint-policy.ts +66 -0
  128. package/src/index.ts +51 -0
  129. package/src/integrations/axios.ts +85 -0
  130. package/src/integrations/fetch.ts +97 -0
  131. package/src/integrations/jquery/index.ts +62 -0
  132. package/src/integrations/jquery/instrument.ts +84 -0
  133. package/src/integrations/react/context.ts +17 -0
  134. package/src/integrations/react/scope.tsx +32 -0
  135. package/src/integrations/request-key.ts +46 -0
  136. package/src/sinks/datadog.ts +71 -0
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @servicetitan/journey
2
+
3
+ Critical user journey monitoring for Datadog RUM (`user_journey` custom actions).
4
+
5
+ - **Docs:** [Journey](https://docs.st.dev/docs/frontend/journey) (source: [`packages/docs/docs/journey.mdx`](../docs/docs/journey.mdx))
6
+
7
+ Prefer `defineJourney` handles (`.start` / `.step` / `.complete`). Soft ambient attributes HTTP only when exactly one step is in flight — use `step.tag()` after `await` or when steps overlap.
@@ -0,0 +1,16 @@
1
+ /** Standard journey def used across engine suites. */
2
+ export declare const baseJourneyDef: {
3
+ readonly name: "journey-under-test";
4
+ readonly team: "platform";
5
+ readonly group: "test";
6
+ readonly service: "journey";
7
+ readonly timeoutMs: 0;
8
+ };
9
+ /** Last emitted journey payload from a sink mock. */
10
+ export declare function lastJourney(emitMock: jest.Mock): any;
11
+ /**
12
+ * Wire `emitMock` as the only sink and restore package defaults after each test.
13
+ * Call once at the top of a `describe` block.
14
+ */
15
+ export declare function useJourneyTestRuntime(emitMock: jest.Mock): void;
16
+ //# sourceMappingURL=test-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-runtime.d.ts","sourceRoot":"","sources":["../../src/__mocks__/test-runtime.ts"],"names":[],"mappings":"AAGA,sDAAsD;AACtD,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAEX,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,OAE9C;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,QAexD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ambient.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ambient.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/ambient.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=axios.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/axios.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/config.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/context.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=datadog.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datadog.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/datadog.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=define-journey.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-journey.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/define-journey.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=expose-app-journey.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expose-app-journey.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/expose-app-journey.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fetch.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/fetch.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jquery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jquery.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/jquery.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=registry.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/registry.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=request-key.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-key.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/request-key.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=requests.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requests.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/requests.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runtime.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/runtime.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=scope.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/scope.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sinks.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sinks.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/sinks.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=step.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/step.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=timeouts.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeouts.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/timeouts.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { type JourneySink } from './core/registry';
2
+ import { type AppRequestTimeouts, type EndpointPolicy } from './endpoint-policy';
3
+ import { type AxiosLikeInstance } from './integrations/axios';
4
+ import { type InstrumentFetchOptions } from './integrations/fetch';
5
+ import { type JqueryStatic, type WindowWithAppJourney } from './integrations/jquery';
6
+ export { longestEndpointMatch, sortEndpointsByLongestMatch } from './endpoint-policy';
7
+ export type { AppRequestTimeouts, EndpointPolicy };
8
+ /** Optional app-wide / per-bundle configuration. */
9
+ export interface JourneyConfig {
10
+ /** App-wide request-timeout fallback. Defaults to { defaultMs: 4000, endpoints: [] }. */
11
+ requestTimeouts?: AppRequestTimeouts;
12
+ /**
13
+ * Replace the sink list used when a journey finishes.
14
+ * Only applied when provided — omit to leave the current list unchanged.
15
+ * Package default is `[sendToDatadog]`; pass `[]` to disable emission.
16
+ */
17
+ sinks?: readonly JourneySink[];
18
+ /**
19
+ * Wire this bundle's axios instance (host or MFE). Same as `instrumentAxios(axios)`.
20
+ * Register any async request interceptors (e.g. auth) before `configureJourney`.
21
+ */
22
+ axios?: AxiosLikeInstance;
23
+ /**
24
+ * Wire fetch. `true` wraps `globalThis.fetch`; pass options for a scoped target / baseURL.
25
+ * Same as `instrumentFetch(...)`.
26
+ */
27
+ fetch?: true | InstrumentFetchOptions;
28
+ /** Wire this bundle's jQuery static. Same as `instrumentJquery($)`. */
29
+ jquery?: JqueryStatic;
30
+ /**
31
+ * Publish `window.App.Journey` for Knockout / legacy hosts.
32
+ * `true` uses the real window; pass a target object in tests.
33
+ */
34
+ exposeAppJourney?: boolean | WindowWithAppJourney;
35
+ }
36
+ /**
37
+ * Apply bundle options: request thresholds, sinks, and/or HTTP / legacy wiring.
38
+ * Optional — call once at startup. Pass this bundle's own axios / `$` / fetch target.
39
+ */
40
+ export declare function configureJourney(config: JourneyConfig): void;
41
+ export declare function getRequestTimeouts(): AppRequestTimeouts;
42
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAEH,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAGH,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC5B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AACtF,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC;AAEnD,oDAAoD;AACpD,MAAM,WAAW,aAAa;IAC1B,yFAAyF;IACzF,eAAe,CAAC,EAAE,kBAAkB,CAAC;IACrC;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,sBAAsB,CAAC;IACtC,uEAAuE;IACvE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG,oBAAoB,CAAC;CACrD;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAsB5D;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD"}
package/dist/config.js ADDED
@@ -0,0 +1,46 @@
1
+ import { defaultRuntime } from './core/runtime';
2
+ import { setJourneySinks } from './core/registry';
3
+ import { sortEndpointsByLongestMatch } from './endpoint-policy';
4
+ import { instrumentAxios } from './integrations/axios';
5
+ import { instrumentFetch } from './integrations/fetch';
6
+ import { exposeAppJourney, instrumentJquery } from './integrations/jquery';
7
+ import { sendToDatadog } from './sinks/datadog';
8
+ export { longestEndpointMatch, sortEndpointsByLongestMatch } from './endpoint-policy';
9
+ /*
10
+ * Default emission target. Kept as a module side effect so any import of this file
11
+ * (see index.ts `import './config'`) installs Datadog. configureJourney only replaces
12
+ * sinks when `sinks` is passed explicitly.
13
+ */ setJourneySinks([
14
+ sendToDatadog
15
+ ]);
16
+ /**
17
+ * Apply bundle options: request thresholds, sinks, and/or HTTP / legacy wiring.
18
+ * Optional — call once at startup. Pass this bundle's own axios / `$` / fetch target.
19
+ */ export function configureJourney(config) {
20
+ if (config.requestTimeouts !== undefined) {
21
+ defaultRuntime.setRequestTimeouts({
22
+ ...config.requestTimeouts,
23
+ endpoints: sortEndpointsByLongestMatch(config.requestTimeouts.endpoints)
24
+ });
25
+ }
26
+ if (config.sinks !== undefined) {
27
+ setJourneySinks(config.sinks);
28
+ }
29
+ if (config.axios !== undefined) {
30
+ instrumentAxios(config.axios);
31
+ }
32
+ if (config.fetch !== undefined) {
33
+ instrumentFetch(config.fetch === true ? {} : config.fetch);
34
+ }
35
+ if (config.jquery !== undefined) {
36
+ instrumentJquery(config.jquery);
37
+ }
38
+ if (config.exposeAppJourney) {
39
+ exposeAppJourney(config.exposeAppJourney === true ? undefined : config.exposeAppJourney);
40
+ }
41
+ }
42
+ export function getRequestTimeouts() {
43
+ return defaultRuntime.getRequestTimeouts();
44
+ }
45
+
46
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config.ts"],"sourcesContent":["import { defaultRuntime } from './core/runtime';\nimport { setJourneySinks, type JourneySink } from './core/registry';\nimport {\n sortEndpointsByLongestMatch,\n type AppRequestTimeouts,\n type EndpointPolicy,\n} from './endpoint-policy';\nimport { instrumentAxios, type AxiosLikeInstance } from './integrations/axios';\nimport { instrumentFetch, type InstrumentFetchOptions } from './integrations/fetch';\nimport {\n exposeAppJourney,\n instrumentJquery,\n type JqueryStatic,\n type WindowWithAppJourney,\n} from './integrations/jquery';\nimport { sendToDatadog } from './sinks/datadog';\n\nexport { longestEndpointMatch, sortEndpointsByLongestMatch } from './endpoint-policy';\nexport type { AppRequestTimeouts, EndpointPolicy };\n\n/** Optional app-wide / per-bundle configuration. */\nexport interface JourneyConfig {\n /** App-wide request-timeout fallback. Defaults to { defaultMs: 4000, endpoints: [] }. */\n requestTimeouts?: AppRequestTimeouts;\n /**\n * Replace the sink list used when a journey finishes.\n * Only applied when provided — omit to leave the current list unchanged.\n * Package default is `[sendToDatadog]`; pass `[]` to disable emission.\n */\n sinks?: readonly JourneySink[];\n /**\n * Wire this bundle's axios instance (host or MFE). Same as `instrumentAxios(axios)`.\n * Register any async request interceptors (e.g. auth) before `configureJourney`.\n */\n axios?: AxiosLikeInstance;\n /**\n * Wire fetch. `true` wraps `globalThis.fetch`; pass options for a scoped target / baseURL.\n * Same as `instrumentFetch(...)`.\n */\n fetch?: true | InstrumentFetchOptions;\n /** Wire this bundle's jQuery static. Same as `instrumentJquery($)`. */\n jquery?: JqueryStatic;\n /**\n * Publish `window.App.Journey` for Knockout / legacy hosts.\n * `true` uses the real window; pass a target object in tests.\n */\n exposeAppJourney?: boolean | WindowWithAppJourney;\n}\n\n/*\n * Default emission target. Kept as a module side effect so any import of this file\n * (see index.ts `import './config'`) installs Datadog. configureJourney only replaces\n * sinks when `sinks` is passed explicitly.\n */\nsetJourneySinks([sendToDatadog]);\n\n/**\n * Apply bundle options: request thresholds, sinks, and/or HTTP / legacy wiring.\n * Optional — call once at startup. Pass this bundle's own axios / `$` / fetch target.\n */\nexport function configureJourney(config: JourneyConfig): void {\n if (config.requestTimeouts !== undefined) {\n defaultRuntime.setRequestTimeouts({\n ...config.requestTimeouts,\n endpoints: sortEndpointsByLongestMatch(config.requestTimeouts.endpoints),\n });\n }\n if (config.sinks !== undefined) {\n setJourneySinks(config.sinks);\n }\n if (config.axios !== undefined) {\n instrumentAxios(config.axios);\n }\n if (config.fetch !== undefined) {\n instrumentFetch(config.fetch === true ? {} : config.fetch);\n }\n if (config.jquery !== undefined) {\n instrumentJquery(config.jquery);\n }\n if (config.exposeAppJourney) {\n exposeAppJourney(config.exposeAppJourney === true ? undefined : config.exposeAppJourney);\n }\n}\n\nexport function getRequestTimeouts(): AppRequestTimeouts {\n return defaultRuntime.getRequestTimeouts();\n}\n"],"names":["defaultRuntime","setJourneySinks","sortEndpointsByLongestMatch","instrumentAxios","instrumentFetch","exposeAppJourney","instrumentJquery","sendToDatadog","longestEndpointMatch","configureJourney","config","requestTimeouts","undefined","setRequestTimeouts","endpoints","sinks","axios","fetch","jquery","getRequestTimeouts"],"mappings":"AAAA,SAASA,cAAc,QAAQ,iBAAiB;AAChD,SAASC,eAAe,QAA0B,kBAAkB;AACpE,SACIC,2BAA2B,QAGxB,oBAAoB;AAC3B,SAASC,eAAe,QAAgC,uBAAuB;AAC/E,SAASC,eAAe,QAAqC,uBAAuB;AACpF,SACIC,gBAAgB,EAChBC,gBAAgB,QAGb,wBAAwB;AAC/B,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,SAASC,oBAAoB,EAAEN,2BAA2B,QAAQ,oBAAoB;AAgCtF;;;;CAIC,GACDD,gBAAgB;IAACM;CAAc;AAE/B;;;CAGC,GACD,OAAO,SAASE,iBAAiBC,MAAqB;IAClD,IAAIA,OAAOC,eAAe,KAAKC,WAAW;QACtCZ,eAAea,kBAAkB,CAAC;YAC9B,GAAGH,OAAOC,eAAe;YACzBG,WAAWZ,4BAA4BQ,OAAOC,eAAe,CAACG,SAAS;QAC3E;IACJ;IACA,IAAIJ,OAAOK,KAAK,KAAKH,WAAW;QAC5BX,gBAAgBS,OAAOK,KAAK;IAChC;IACA,IAAIL,OAAOM,KAAK,KAAKJ,WAAW;QAC5BT,gBAAgBO,OAAOM,KAAK;IAChC;IACA,IAAIN,OAAOO,KAAK,KAAKL,WAAW;QAC5BR,gBAAgBM,OAAOO,KAAK,KAAK,OAAO,CAAC,IAAIP,OAAOO,KAAK;IAC7D;IACA,IAAIP,OAAOQ,MAAM,KAAKN,WAAW;QAC7BN,iBAAiBI,OAAOQ,MAAM;IAClC;IACA,IAAIR,OAAOL,gBAAgB,EAAE;QACzBA,iBAAiBK,OAAOL,gBAAgB,KAAK,OAAOO,YAAYF,OAAOL,gBAAgB;IAC3F;AACJ;AAEA,OAAO,SAASc;IACZ,OAAOnB,eAAemB,kBAAkB;AAC5C"}
@@ -0,0 +1,6 @@
1
+ /** Core engine barrel — free helpers over the default runtime, plus handles and types. */
2
+ export { activeJourneyStep, addJourneySink, completeJourney, defineJourney, emitJourneyEvent, excludeJourney, failJourney, firstOpenJourney, journeyMountStep, journeyStep, reportBackendRequest, setJourneySinks, setJourneyTags, startJourney, type JourneyHandle, type JourneySink, } from './registry';
3
+ export { createJourneyRuntime, defaultRuntime, resetJourney, type JourneyRuntime, type JourneyRuntimeOptions, } from './runtime';
4
+ export type { JourneyDef, JourneyEvent, JourneyNameLike, JourneyStepEvent, JourneyStepOptions, JourneyStepRef, JourneyStepTarget, StepHandle, TagValue, } from './types';
5
+ export { JourneyStepTag, resolveJourneyStep } from './step-tag';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,OAAO,EACH,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,WAAW,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACH,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC7B,MAAM,WAAW,CAAC;AACnB,YAAY,EACR,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,QAAQ,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Core engine barrel — free helpers over the default runtime, plus handles and types. */ export { activeJourneyStep, addJourneySink, completeJourney, defineJourney, emitJourneyEvent, excludeJourney, failJourney, firstOpenJourney, journeyMountStep, journeyStep, reportBackendRequest, setJourneySinks, setJourneyTags, startJourney } from './registry';
2
+ export { createJourneyRuntime, defaultRuntime, resetJourney } from './runtime';
3
+ export { JourneyStepTag, resolveJourneyStep } from './step-tag';
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["/** Core engine barrel — free helpers over the default runtime, plus handles and types. */\n\nexport {\n activeJourneyStep,\n addJourneySink,\n completeJourney,\n defineJourney,\n emitJourneyEvent,\n excludeJourney,\n failJourney,\n firstOpenJourney,\n journeyMountStep,\n journeyStep,\n reportBackendRequest,\n setJourneySinks,\n setJourneyTags,\n startJourney,\n type JourneyHandle,\n type JourneySink,\n} from './registry';\nexport {\n createJourneyRuntime,\n defaultRuntime,\n resetJourney,\n type JourneyRuntime,\n type JourneyRuntimeOptions,\n} from './runtime';\nexport type {\n JourneyDef,\n JourneyEvent,\n JourneyNameLike,\n JourneyStepEvent,\n JourneyStepOptions,\n JourneyStepRef,\n JourneyStepTarget,\n StepHandle,\n TagValue,\n} from './types';\nexport { JourneyStepTag, resolveJourneyStep } from './step-tag';\n"],"names":["activeJourneyStep","addJourneySink","completeJourney","defineJourney","emitJourneyEvent","excludeJourney","failJourney","firstOpenJourney","journeyMountStep","journeyStep","reportBackendRequest","setJourneySinks","setJourneyTags","startJourney","createJourneyRuntime","defaultRuntime","resetJourney","JourneyStepTag","resolveJourneyStep"],"mappings":"AAAA,wFAAwF,GAExF,SACIA,iBAAiB,EACjBC,cAAc,EACdC,eAAe,EACfC,aAAa,EACbC,gBAAgB,EAChBC,cAAc,EACdC,WAAW,EACXC,gBAAgB,EAChBC,gBAAgB,EAChBC,WAAW,EACXC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,EACdC,YAAY,QAGT,aAAa;AACpB,SACIC,oBAAoB,EACpBC,cAAc,EACdC,YAAY,QAGT,YAAY;AAYnB,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,aAAa"}
@@ -0,0 +1,50 @@
1
+ import type { JourneyDef, JourneyEvent, JourneyHandle, JourneySink, JourneyState, JourneyStepOptions, JourneyStepRef, JourneyStepTarget, StepHandle, TagValue } from './types';
2
+ export type { JourneyHandle, JourneySink };
3
+ /** Look up an open journey by name. */
4
+ export declare function getOpenJourney(name: string): JourneyState | undefined;
5
+ /** First open journey among `names` (order preserved), or null. */
6
+ export declare function firstOpenJourney(names: readonly string[]): string | null;
7
+ /**
8
+ * Active step for soft-ambient HTTP attribution, or null when 0 or 2+ steps are in flight
9
+ * app-wide. Untagged traffic is attributed to that lone step even if unrelated — prefer
10
+ * `step.tag()` when the page has background instrumented requests. Adapters call this when
11
+ * a request has no explicit stamp.
12
+ */
13
+ export declare function activeJourneyStep(): JourneyStepRef | null;
14
+ /**
15
+ * Record a finished backend request against a captured step.
16
+ * 5xx / network / slow (over threshold) mark Bad; 4xx is not counted. Fail-fast on breach.
17
+ */
18
+ export declare function reportBackendRequest(step: JourneyStepRef | undefined, status: number | undefined, durationMs: number, requestKey: string): void;
19
+ /**
20
+ * Run one step of a named journey. Runs untraced (noop handle) when no matching journey is open.
21
+ * `journey` may be a name, null, or an ordered candidate list.
22
+ * Prefer `defineJourney(...).step` when you own the journey config.
23
+ */
24
+ export declare function journeyStep<T>(journey: JourneyStepTarget, stepName: string, fn: (step: StepHandle) => T | Promise<T>, opts?: JourneyStepOptions): Promise<T>;
25
+ /**
26
+ * journeyStep deferred by one microtask so a parent `<JourneyScope>` opens first
27
+ * (React runs child mount effects before parent). Use for mount-effect steps only.
28
+ */
29
+ export declare function journeyMountStep<T>(journey: JourneyStepTarget, stepName: string, fn: (step: StepHandle) => T | Promise<T>, opts?: JourneyStepOptions): Promise<T>;
30
+ /** Replace the sink list (e.g. host bootstrap or tests). Pass `[]` to disable emission. */
31
+ export declare function setJourneySinks(next: readonly JourneySink[]): void;
32
+ /** Append a sink alongside the current ones. */
33
+ export declare function addJourneySink(sink: JourneySink): void;
34
+ /** Emit a terminal journey event to every configured sink. */
35
+ export declare function emitJourneyEvent(payload: JourneyEvent): void;
36
+ /** Merge custom tags onto an open journey. No-op if not open. Prefer `handle.setTags`. */
37
+ export declare function setJourneyTags(name: string | null, tags: Record<string, TagValue>): void;
38
+ /** Begin a journey. Restarts (closes) an already-open journey of the same name. */
39
+ export declare function startJourney(def: JourneyDef): void;
40
+ /** Fail-fast: record reason and emit immediately. Idempotent via `closed`. */
41
+ export declare function failJourneyNow(journey: JourneyState, reason: string): void;
42
+ /** Mark a named journey Bad for a custom reason (fail-fast). Prefer `handle.fail`. */
43
+ export declare function failJourney(name: string, reason: string): void;
44
+ /** Successful end. Outcome stays Bad if a breach already occurred. No-op when name is null. Prefer `handle.complete`. */
45
+ export declare function completeJourney(name: string | null, tags?: Record<string, TagValue>): void;
46
+ /** User left before finishing. Stays Bad if a breach already occurred (breach-anchored). Prefer `handle.exclude`. */
47
+ export declare function excludeJourney(name: string): void;
48
+ /** Turn a journey config into a handle with bound lifecycle methods. Preferred public API. */
49
+ export declare function defineJourney(def: JourneyDef): JourneyHandle;
50
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACX,MAAM,SAAS,CAAC;AAEjB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC;AAE3C,uCAAuC;AACvC,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAErE;AAED,mEAAmE;AACnE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAExE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAEzD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,cAAc,GAAG,SAAS,EAChC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACnB,IAAI,CAEN;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAC/B,OAAO,EAAE,iBAA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Q,CAAC,GAAG,IAAI,CAE1F;AAED,qHAAqH;AACrH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED,8FAA8F;AAC9F,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,aAAa,CAuC5D"}
@@ -0,0 +1,102 @@
1
+ import { defaultRuntime } from './runtime';
2
+ /** Look up an open journey by name. */ export function getOpenJourney(name) {
3
+ return defaultRuntime.getOpenJourney(name);
4
+ }
5
+ /** First open journey among `names` (order preserved), or null. */ export function firstOpenJourney(names) {
6
+ return defaultRuntime.firstOpenJourney(names);
7
+ }
8
+ /**
9
+ * Active step for soft-ambient HTTP attribution, or null when 0 or 2+ steps are in flight
10
+ * app-wide. Untagged traffic is attributed to that lone step even if unrelated — prefer
11
+ * `step.tag()` when the page has background instrumented requests. Adapters call this when
12
+ * a request has no explicit stamp.
13
+ */ export function activeJourneyStep() {
14
+ return defaultRuntime.activeJourneyStep();
15
+ }
16
+ /**
17
+ * Record a finished backend request against a captured step.
18
+ * 5xx / network / slow (over threshold) mark Bad; 4xx is not counted. Fail-fast on breach.
19
+ */ export function reportBackendRequest(step, status, durationMs, requestKey) {
20
+ defaultRuntime.reportBackendRequest(step, status, durationMs, requestKey);
21
+ }
22
+ /**
23
+ * Run one step of a named journey. Runs untraced (noop handle) when no matching journey is open.
24
+ * `journey` may be a name, null, or an ordered candidate list.
25
+ * Prefer `defineJourney(...).step` when you own the journey config.
26
+ */ export async function journeyStep(journey, stepName, fn, opts) {
27
+ return defaultRuntime.journeyStep(journey, stepName, fn, opts);
28
+ }
29
+ /**
30
+ * journeyStep deferred by one microtask so a parent `<JourneyScope>` opens first
31
+ * (React runs child mount effects before parent). Use for mount-effect steps only.
32
+ */ export async function journeyMountStep(journey, stepName, fn, opts) {
33
+ return defaultRuntime.journeyMountStep(journey, stepName, fn, opts);
34
+ }
35
+ /** Replace the sink list (e.g. host bootstrap or tests). Pass `[]` to disable emission. */ export function setJourneySinks(next) {
36
+ defaultRuntime.setSinks(next);
37
+ }
38
+ /** Append a sink alongside the current ones. */ export function addJourneySink(sink) {
39
+ defaultRuntime.addSink(sink);
40
+ }
41
+ /** Emit a terminal journey event to every configured sink. */ export function emitJourneyEvent(payload) {
42
+ defaultRuntime.emit(payload);
43
+ }
44
+ /** Merge custom tags onto an open journey. No-op if not open. Prefer `handle.setTags`. */ export function setJourneyTags(name, tags) {
45
+ defaultRuntime.setJourneyTags(name, tags);
46
+ }
47
+ /** Begin a journey. Restarts (closes) an already-open journey of the same name. */ export function startJourney(def) {
48
+ defaultRuntime.startJourney(def);
49
+ }
50
+ /** Fail-fast: record reason and emit immediately. Idempotent via `closed`. */ export function failJourneyNow(journey, reason) {
51
+ defaultRuntime.failJourneyNow(journey, reason);
52
+ }
53
+ /** Mark a named journey Bad for a custom reason (fail-fast). Prefer `handle.fail`. */ export function failJourney(name, reason) {
54
+ defaultRuntime.failJourney(name, reason);
55
+ }
56
+ /** Successful end. Outcome stays Bad if a breach already occurred. No-op when name is null. Prefer `handle.complete`. */ export function completeJourney(name, tags) {
57
+ defaultRuntime.completeJourney(name, tags);
58
+ }
59
+ /** User left before finishing. Stays Bad if a breach already occurred (breach-anchored). Prefer `handle.exclude`. */ export function excludeJourney(name) {
60
+ defaultRuntime.excludeJourney(name);
61
+ }
62
+ /** Turn a journey config into a handle with bound lifecycle methods. Preferred public API. */ export function defineJourney(def) {
63
+ const ensureStarted = ()=>{
64
+ if (!getOpenJourney(def.name)) {
65
+ startJourney(def);
66
+ }
67
+ };
68
+ const handle = {
69
+ ...def,
70
+ start (tags) {
71
+ startJourney(def);
72
+ if (tags) {
73
+ setJourneyTags(def.name, tags);
74
+ }
75
+ },
76
+ step (stepName, fn, opts) {
77
+ ensureStarted();
78
+ return journeyStep(def.name, stepName, fn, opts);
79
+ },
80
+ async mountStep (stepName, fn, opts) {
81
+ // Defer so a parent <JourneyScope> opens first (child effects run before parent).
82
+ await Promise.resolve();
83
+ ensureStarted();
84
+ return journeyStep(def.name, stepName, fn, opts);
85
+ },
86
+ complete (tags) {
87
+ completeJourney(def.name, tags);
88
+ },
89
+ fail (reason) {
90
+ failJourney(def.name, reason);
91
+ },
92
+ exclude () {
93
+ excludeJourney(def.name);
94
+ },
95
+ setTags (tags) {
96
+ setJourneyTags(def.name, tags);
97
+ }
98
+ };
99
+ return handle;
100
+ }
101
+
102
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/registry.ts"],"sourcesContent":["import { defaultRuntime } from './runtime';\nimport type {\n JourneyDef,\n JourneyEvent,\n JourneyHandle,\n JourneySink,\n JourneyState,\n JourneyStepOptions,\n JourneyStepRef,\n JourneyStepTarget,\n StepHandle,\n TagValue,\n} from './types';\n\nexport type { JourneyHandle, JourneySink };\n\n/** Look up an open journey by name. */\nexport function getOpenJourney(name: string): JourneyState | undefined {\n return defaultRuntime.getOpenJourney(name);\n}\n\n/** First open journey among `names` (order preserved), or null. */\nexport function firstOpenJourney(names: readonly string[]): string | null {\n return defaultRuntime.firstOpenJourney(names);\n}\n\n/**\n * Active step for soft-ambient HTTP attribution, or null when 0 or 2+ steps are in flight\n * app-wide. Untagged traffic is attributed to that lone step even if unrelated — prefer\n * `step.tag()` when the page has background instrumented requests. Adapters call this when\n * a request has no explicit stamp.\n */\nexport function activeJourneyStep(): JourneyStepRef | null {\n return defaultRuntime.activeJourneyStep();\n}\n\n/**\n * Record a finished backend request against a captured step.\n * 5xx / network / slow (over threshold) mark Bad; 4xx is not counted. Fail-fast on breach.\n */\nexport function reportBackendRequest(\n step: JourneyStepRef | undefined,\n status: number | undefined,\n durationMs: number,\n requestKey: string\n): void {\n defaultRuntime.reportBackendRequest(step, status, durationMs, requestKey);\n}\n\n/**\n * Run one step of a named journey. Runs untraced (noop handle) when no matching journey is open.\n * `journey` may be a name, null, or an ordered candidate list.\n * Prefer `defineJourney(...).step` when you own the journey config.\n */\nexport async function journeyStep<T>(\n journey: JourneyStepTarget,\n stepName: string,\n fn: (step: StepHandle) => T | Promise<T>,\n opts?: JourneyStepOptions\n): Promise<T> {\n return defaultRuntime.journeyStep(journey, stepName, fn, opts);\n}\n\n/**\n * journeyStep deferred by one microtask so a parent `<JourneyScope>` opens first\n * (React runs child mount effects before parent). Use for mount-effect steps only.\n */\nexport async function journeyMountStep<T>(\n journey: JourneyStepTarget,\n stepName: string,\n fn: (step: StepHandle) => T | Promise<T>,\n opts?: JourneyStepOptions\n): Promise<T> {\n return defaultRuntime.journeyMountStep(journey, stepName, fn, opts);\n}\n\n/** Replace the sink list (e.g. host bootstrap or tests). Pass `[]` to disable emission. */\nexport function setJourneySinks(next: readonly JourneySink[]): void {\n defaultRuntime.setSinks(next);\n}\n\n/** Append a sink alongside the current ones. */\nexport function addJourneySink(sink: JourneySink): void {\n defaultRuntime.addSink(sink);\n}\n\n/** Emit a terminal journey event to every configured sink. */\nexport function emitJourneyEvent(payload: JourneyEvent): void {\n defaultRuntime.emit(payload);\n}\n\n/** Merge custom tags onto an open journey. No-op if not open. Prefer `handle.setTags`. */\nexport function setJourneyTags(name: string | null, tags: Record<string, TagValue>): void {\n defaultRuntime.setJourneyTags(name, tags);\n}\n\n/** Begin a journey. Restarts (closes) an already-open journey of the same name. */\nexport function startJourney(def: JourneyDef): void {\n defaultRuntime.startJourney(def);\n}\n\n/** Fail-fast: record reason and emit immediately. Idempotent via `closed`. */\nexport function failJourneyNow(journey: JourneyState, reason: string): void {\n defaultRuntime.failJourneyNow(journey, reason);\n}\n\n/** Mark a named journey Bad for a custom reason (fail-fast). Prefer `handle.fail`. */\nexport function failJourney(name: string, reason: string): void {\n defaultRuntime.failJourney(name, reason);\n}\n\n/** Successful end. Outcome stays Bad if a breach already occurred. No-op when name is null. Prefer `handle.complete`. */\nexport function completeJourney(name: string | null, tags?: Record<string, TagValue>): void {\n defaultRuntime.completeJourney(name, tags);\n}\n\n/** User left before finishing. Stays Bad if a breach already occurred (breach-anchored). Prefer `handle.exclude`. */\nexport function excludeJourney(name: string): void {\n defaultRuntime.excludeJourney(name);\n}\n\n/** Turn a journey config into a handle with bound lifecycle methods. Preferred public API. */\nexport function defineJourney(def: JourneyDef): JourneyHandle {\n const ensureStarted = () => {\n if (!getOpenJourney(def.name)) {\n startJourney(def);\n }\n };\n\n const handle: JourneyHandle = {\n ...def,\n start(tags) {\n startJourney(def);\n if (tags) {\n setJourneyTags(def.name, tags);\n }\n },\n step(stepName, fn, opts) {\n ensureStarted();\n return journeyStep(def.name, stepName, fn, opts);\n },\n async mountStep(stepName, fn, opts) {\n // Defer so a parent <JourneyScope> opens first (child effects run before parent).\n await Promise.resolve();\n ensureStarted();\n return journeyStep(def.name, stepName, fn, opts);\n },\n complete(tags) {\n completeJourney(def.name, tags);\n },\n fail(reason) {\n failJourney(def.name, reason);\n },\n exclude() {\n excludeJourney(def.name);\n },\n setTags(tags) {\n setJourneyTags(def.name, tags);\n },\n };\n return handle;\n}\n"],"names":["defaultRuntime","getOpenJourney","name","firstOpenJourney","names","activeJourneyStep","reportBackendRequest","step","status","durationMs","requestKey","journeyStep","journey","stepName","fn","opts","journeyMountStep","setJourneySinks","next","setSinks","addJourneySink","sink","addSink","emitJourneyEvent","payload","emit","setJourneyTags","tags","startJourney","def","failJourneyNow","reason","failJourney","completeJourney","excludeJourney","defineJourney","ensureStarted","handle","start","mountStep","Promise","resolve","complete","fail","exclude","setTags"],"mappings":"AAAA,SAASA,cAAc,QAAQ,YAAY;AAgB3C,qCAAqC,GACrC,OAAO,SAASC,eAAeC,IAAY;IACvC,OAAOF,eAAeC,cAAc,CAACC;AACzC;AAEA,iEAAiE,GACjE,OAAO,SAASC,iBAAiBC,KAAwB;IACrD,OAAOJ,eAAeG,gBAAgB,CAACC;AAC3C;AAEA;;;;;CAKC,GACD,OAAO,SAASC;IACZ,OAAOL,eAAeK,iBAAiB;AAC3C;AAEA;;;CAGC,GACD,OAAO,SAASC,qBACZC,IAAgC,EAChCC,MAA0B,EAC1BC,UAAkB,EAClBC,UAA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F,GAC5F,OAAO,SAASiC,cAAcN,GAAe;IACzC,MAAMO,gBAAgB;QAClB,IAAI,CAACnC,eAAe4B,IAAI3B,IAAI,GAAG;YAC3B0B,aAAaC;QACjB;IACJ;IAEA,MAAMQ,SAAwB;QAC1B,GAAGR,GAAG;QACNS,OAAMX,IAAI;YACNC,aAAaC;YACb,IAAIF,MAAM;gBACND,eAAeG,IAAI3B,IAAI,EAAEyB;YAC7B;QACJ;QACApB,MAAKM,QAAQ,EAAEC,EAAE,EAAEC,IAAI;YACnBqB;YACA,OAAOzB,YAAYkB,IAAI3B,IAAI,EAAEW,UAAUC,IAAIC;QAC/C;QACA,MAAMwB,WAAU1B,QAAQ,EAAEC,EAAE,EAAEC,IAAI;YAC9B,kFAAkF;YAClF,MAAMyB,QAAQC,OAAO;YACrBL;YACA,OAAOzB,YAAYkB,IAAI3B,IAAI,EAAEW,UAAUC,IAAIC;QAC/C;QACA2B,UAASf,IAAI;YACTM,gBAAgBJ,IAAI3B,IAAI,EAAEyB;QAC9B;QACAgB,MAAKZ,MAAM;YACPC,YAAYH,IAAI3B,IAAI,EAAE6B;QAC1B;QACAa;YACIV,eAAeL,IAAI3B,IAAI;QAC3B;QACA2C,SAAQlB,IAAI;YACRD,eAAeG,IAAI3B,IAAI,EAAEyB;QAC7B;IACJ;IACA,OAAOU;AACX"}
@@ -0,0 +1,51 @@
1
+ import { type AppRequestTimeouts } from '../endpoint-policy';
2
+ import type { JourneyDef, JourneyEvent, JourneySink, JourneyState, JourneyStepOptions, JourneyStepRef, JourneyStepTarget, StepHandle, TagValue } from './types';
3
+ /** @internal Private — not part of the public package API. */
4
+ export interface JourneyRuntimeOptions {
5
+ /** Initial sinks. Defaults to `[]` — package bootstrap installs Datadog on the default runtime. */
6
+ sinks?: readonly JourneySink[];
7
+ requestTimeouts?: AppRequestTimeouts;
8
+ }
9
+ /**
10
+ * @internal Private — not part of the public package API.
11
+ * Isolated journey engine (open journeys, ambient steps, sinks, request thresholds).
12
+ * App code should keep using free helpers (`defineJourney`, `journeyStep`, …) — they
13
+ * bind to the process default runtime. Prefer `resetJourney()` in tests.
14
+ */
15
+ export interface JourneyRuntime {
16
+ getRequestTimeouts(): AppRequestTimeouts;
17
+ setRequestTimeouts(next: AppRequestTimeouts): void;
18
+ setSinks(next: readonly JourneySink[]): void;
19
+ addSink(sink: JourneySink): void;
20
+ emit(payload: JourneyEvent): void;
21
+ getOpenJourney(name: string): JourneyState | undefined;
22
+ firstOpenJourney(names: readonly string[]): string | null;
23
+ setJourneyTags(name: string | null, tags: Record<string, TagValue>): void;
24
+ startJourney(def: JourneyDef): void;
25
+ failJourneyNow(journey: JourneyState, reason: string): void;
26
+ failJourney(name: string, reason: string): void;
27
+ completeJourney(name: string | null, tags?: Record<string, TagValue>): void;
28
+ excludeJourney(name: string): void;
29
+ activeJourneyStep(): JourneyStepRef | null;
30
+ journeyStep<T>(journey: JourneyStepTarget, stepName: string, fn: (step: StepHandle) => T | Promise<T>, opts?: JourneyStepOptions): Promise<T>;
31
+ journeyMountStep<T>(journey: JourneyStepTarget, stepName: string, fn: (step: StepHandle) => T | Promise<T>, opts?: JourneyStepOptions): Promise<T>;
32
+ reportBackendRequest(step: JourneyStepRef | undefined, status: number | undefined, durationMs: number, requestKey: string): void;
33
+ /** Close open journeys, clear ambient steps, restore default timeouts/sinks. */
34
+ reset(options?: JourneyRuntimeOptions): void;
35
+ }
36
+ /**
37
+ * @internal Private — not part of the public package API.
38
+ * Build an isolated engine. Rarely needed — apps use the default via free helpers.
39
+ */
40
+ export declare function createJourneyRuntime(options?: JourneyRuntimeOptions): JourneyRuntime;
41
+ /**
42
+ * @internal Private — not part of the public package API.
43
+ * Process-wide engine used by free helpers. App code does not need to touch this.
44
+ */
45
+ export declare const defaultRuntime: JourneyRuntime;
46
+ /**
47
+ * Reset the default engine (open journeys, ambient steps, sinks, request thresholds).
48
+ * Intended for tests — call in `beforeEach` / `afterEach` instead of manual cleanup.
49
+ */
50
+ export declare function resetJourney(options?: Jour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