@servicetitan/journey 2.0.0 → 3.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 (233) hide show
  1. package/README.md +1 -1
  2. package/dist/__test-utils__/test-runtime.d.ts.map +1 -0
  3. package/dist/__test-utils__/test-runtime.js +54 -0
  4. package/dist/__test-utils__/test-runtime.js.map +1 -0
  5. package/dist/__tests__/core/ambient.test.d.ts.map +1 -0
  6. package/dist/__tests__/core/api.test.d.ts +2 -0
  7. package/dist/__tests__/core/api.test.d.ts.map +1 -0
  8. package/dist/__tests__/core/define-journey.test.d.ts.map +1 -0
  9. package/dist/__tests__/core/requests.test.d.ts.map +1 -0
  10. package/dist/__tests__/core/runtime.test.d.ts.map +1 -0
  11. package/dist/__tests__/core/sanitize.test.d.ts +2 -0
  12. package/dist/__tests__/core/sanitize.test.d.ts.map +1 -0
  13. package/dist/__tests__/core/step.test.d.ts.map +1 -0
  14. package/dist/__tests__/core/timeouts.test.d.ts.map +1 -0
  15. package/dist/__tests__/global.test.d.ts +3 -0
  16. package/dist/__tests__/global.test.d.ts.map +1 -0
  17. package/dist/__tests__/hardening.test.d.ts +2 -0
  18. package/dist/__tests__/hardening.test.d.ts.map +1 -0
  19. package/dist/__tests__/integrations/axios.test.d.ts.map +1 -0
  20. package/dist/__tests__/integrations/context.test.d.ts.map +1 -0
  21. package/dist/__tests__/integrations/expose-app-journey.test.d.ts.map +1 -0
  22. package/dist/__tests__/integrations/fetch.test.d.ts.map +1 -0
  23. package/dist/__tests__/integrations/host-mfe.test.d.ts +2 -0
  24. package/dist/__tests__/integrations/host-mfe.test.d.ts.map +1 -0
  25. package/dist/__tests__/integrations/jquery.test.d.ts.map +1 -0
  26. package/dist/__tests__/integrations/request-key.test.d.ts.map +1 -0
  27. package/dist/__tests__/integrations/scope.test.d.ts.map +1 -0
  28. package/dist/__tests__/integrations/use-journey-step.test.d.ts +2 -0
  29. package/dist/__tests__/integrations/use-journey-step.test.d.ts.map +1 -0
  30. package/dist/__tests__/sinks/console.test.d.ts +2 -0
  31. package/dist/__tests__/sinks/console.test.d.ts.map +1 -0
  32. package/dist/__tests__/sinks/datadog.test.d.ts.map +1 -0
  33. package/dist/__tests__/sinks/sinks.test.d.ts.map +1 -0
  34. package/dist/config.d.ts +61 -13
  35. package/dist/config.d.ts.map +1 -1
  36. package/dist/config.js +98 -29
  37. package/dist/config.js.map +1 -1
  38. package/dist/core/abort-error.d.ts +4 -0
  39. package/dist/core/abort-error.d.ts.map +1 -0
  40. package/dist/core/abort-error.js +22 -0
  41. package/dist/core/abort-error.js.map +1 -0
  42. package/dist/core/api.d.ts +43 -0
  43. package/dist/core/api.d.ts.map +1 -0
  44. package/dist/core/api.js +122 -0
  45. package/dist/core/api.js.map +1 -0
  46. package/dist/{endpoint-policy.d.ts → core/endpoint-policy.d.ts} +14 -4
  47. package/dist/core/endpoint-policy.d.ts.map +1 -0
  48. package/dist/core/endpoint-policy.js +70 -0
  49. package/dist/core/endpoint-policy.js.map +1 -0
  50. package/dist/core/index.d.ts +6 -5
  51. package/dist/core/index.d.ts.map +1 -1
  52. package/dist/core/index.js +4 -3
  53. package/dist/core/index.js.map +1 -1
  54. package/dist/core/limits.d.ts +29 -0
  55. package/dist/core/limits.d.ts.map +1 -0
  56. package/dist/core/limits.js +63 -0
  57. package/dist/core/limits.js.map +1 -0
  58. package/dist/core/request-policy.d.ts +39 -0
  59. package/dist/core/request-policy.d.ts.map +1 -0
  60. package/dist/core/request-policy.js +18 -0
  61. package/dist/core/request-policy.js.map +1 -0
  62. package/dist/core/runtime.d.ts +95 -17
  63. package/dist/core/runtime.d.ts.map +1 -1
  64. package/dist/core/runtime.js +435 -124
  65. package/dist/core/runtime.js.map +1 -1
  66. package/dist/core/sanitize.d.ts +23 -0
  67. package/dist/core/sanitize.d.ts.map +1 -0
  68. package/dist/core/sanitize.js +143 -0
  69. package/dist/core/sanitize.js.map +1 -0
  70. package/dist/core/step-tag.d.ts +31 -6
  71. package/dist/core/step-tag.d.ts.map +1 -1
  72. package/dist/core/step-tag.js +62 -9
  73. package/dist/core/step-tag.js.map +1 -1
  74. package/dist/core/types.d.ts +76 -26
  75. package/dist/core/types.d.ts.map +1 -1
  76. package/dist/core/types.js +4 -1
  77. package/dist/core/types.js.map +1 -1
  78. package/dist/global.d.ts +145 -0
  79. package/dist/global.d.ts.map +1 -0
  80. package/dist/global.js +326 -0
  81. package/dist/global.js.map +1 -0
  82. package/dist/index.d.ts +9 -5
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +9 -5
  85. package/dist/index.js.map +1 -1
  86. package/dist/integrations/axios.d.ts +5 -1
  87. package/dist/integrations/axios.d.ts.map +1 -1
  88. package/dist/integrations/axios.js +146 -34
  89. package/dist/integrations/axios.js.map +1 -1
  90. package/dist/integrations/fetch.d.ts +6 -4
  91. package/dist/integrations/fetch.d.ts.map +1 -1
  92. package/dist/integrations/fetch.js +105 -26
  93. package/dist/integrations/fetch.js.map +1 -1
  94. package/dist/integrations/http-report.d.ts +27 -0
  95. package/dist/integrations/http-report.d.ts.map +1 -0
  96. package/dist/integrations/http-report.js +123 -0
  97. package/dist/integrations/http-report.js.map +1 -0
  98. package/dist/integrations/jquery/index.d.ts +10 -6
  99. package/dist/integrations/jquery/index.d.ts.map +1 -1
  100. package/dist/integrations/jquery/index.js +28 -9
  101. package/dist/integrations/jquery/index.js.map +1 -1
  102. package/dist/integrations/jquery/instrument.d.ts +14 -5
  103. package/dist/integrations/jquery/instrument.d.ts.map +1 -1
  104. package/dist/integrations/jquery/instrument.js +111 -29
  105. package/dist/integrations/jquery/instrument.js.map +1 -1
  106. package/dist/integrations/react/context.d.ts +4 -1
  107. package/dist/integrations/react/context.d.ts.map +1 -1
  108. package/dist/integrations/react/context.js +4 -1
  109. package/dist/integrations/react/context.js.map +1 -1
  110. package/dist/integrations/react/scope.d.ts +14 -3
  111. package/dist/integrations/react/scope.d.ts.map +1 -1
  112. package/dist/integrations/react/scope.js +48 -9
  113. package/dist/integrations/react/scope.js.map +1 -1
  114. package/dist/integrations/react/stable-config-keys.d.ts +6 -0
  115. package/dist/integrations/react/stable-config-keys.d.ts.map +1 -0
  116. package/dist/integrations/react/stable-config-keys.js +21 -0
  117. package/dist/integrations/react/stable-config-keys.js.map +1 -0
  118. package/dist/integrations/react/use-journey-step.d.ts +11 -0
  119. package/dist/integrations/react/use-journey-step.d.ts.map +1 -0
  120. package/dist/integrations/react/use-journey-step.js +19 -0
  121. package/dist/integrations/react/use-journey-step.js.map +1 -0
  122. package/dist/integrations/request-key.d.ts +8 -3
  123. package/dist/integrations/request-key.d.ts.map +1 -1
  124. package/dist/integrations/request-key.js +10 -9
  125. package/dist/integrations/request-key.js.map +1 -1
  126. package/dist/integrations/soft-skip.d.ts +7 -0
  127. package/dist/integrations/soft-skip.d.ts.map +1 -0
  128. package/dist/integrations/soft-skip.js +30 -0
  129. package/dist/integrations/soft-skip.js.map +1 -0
  130. package/dist/sinks/console.d.ts +11 -0
  131. package/dist/sinks/console.d.ts.map +1 -0
  132. package/dist/sinks/console.js +19 -0
  133. package/dist/sinks/console.js.map +1 -0
  134. package/dist/sinks/datadog.d.ts +12 -1
  135. package/dist/sinks/datadog.d.ts.map +1 -1
  136. package/dist/sinks/datadog.js +42 -25
  137. package/dist/sinks/datadog.js.map +1 -1
  138. package/package.json +2 -2
  139. package/src/{__mocks__ → __test-utils__}/test-runtime.ts +15 -4
  140. package/src/__tests__/config.test.ts +158 -42
  141. package/src/__tests__/{ambient.test.ts → core/ambient.test.ts} +23 -16
  142. package/src/__tests__/{registry.test.ts → core/api.test.ts} +35 -30
  143. package/src/__tests__/{define-journey.test.ts → core/define-journey.test.ts} +33 -15
  144. package/src/__tests__/{requests.test.ts → core/requests.test.ts} +61 -39
  145. package/src/__tests__/{runtime.test.ts → core/runtime.test.ts} +84 -37
  146. package/src/__tests__/core/sanitize.test.ts +69 -0
  147. package/src/__tests__/{step.test.ts → core/step.test.ts} +146 -52
  148. package/src/__tests__/{timeouts.test.ts → core/timeouts.test.ts} +83 -13
  149. package/src/__tests__/global.test.ts +154 -0
  150. package/src/__tests__/hardening.test.ts +613 -0
  151. package/src/__tests__/integrations/axios.test.ts +616 -0
  152. package/src/__tests__/{context.test.tsx → integrations/context.test.tsx} +1 -1
  153. package/src/__tests__/{expose-app-journey.test.ts → integrations/expose-app-journey.test.ts} +11 -5
  154. package/src/__tests__/{fetch.test.ts → integrations/fetch.test.ts} +159 -25
  155. package/src/__tests__/integrations/host-mfe.test.ts +548 -0
  156. package/src/__tests__/integrations/jquery.test.ts +539 -0
  157. package/src/__tests__/{request-key.test.ts → integrations/request-key.test.ts} +1 -1
  158. package/src/__tests__/integrations/scope.test.tsx +286 -0
  159. package/src/__tests__/integrations/use-journey-step.test.tsx +43 -0
  160. package/src/__tests__/sinks/console.test.ts +103 -0
  161. package/src/__tests__/{datadog.test.ts → sinks/datadog.test.ts} +109 -5
  162. package/src/__tests__/{sinks.test.ts → sinks/sinks.test.ts} +13 -12
  163. package/src/config.ts +173 -41
  164. package/src/core/abort-error.ts +24 -0
  165. package/src/core/api.ts +159 -0
  166. package/src/{endpoint-policy.ts → core/endpoint-policy.ts} +46 -4
  167. package/src/core/index.ts +16 -17
  168. package/src/core/limits.ts +73 -0
  169. package/src/core/request-policy.ts +66 -0
  170. package/src/core/runtime.ts +560 -137
  171. package/src/core/sanitize.ts +177 -0
  172. package/src/core/step-tag.ts +90 -11
  173. package/src/core/types.ts +82 -26
  174. package/src/global.ts +466 -0
  175. package/src/index.ts +31 -18
  176. package/src/integrations/axios.ts +183 -45
  177. package/src/integrations/fetch.ts +127 -41
  178. package/src/integrations/http-report.ts +184 -0
  179. package/src/integrations/jquery/index.ts +37 -18
  180. package/src/integrations/jquery/instrument.ts +126 -42
  181. package/src/integrations/react/context.ts +4 -1
  182. package/src/integrations/react/scope.tsx +61 -10
  183. package/src/integrations/react/stable-config-keys.ts +28 -0
  184. package/src/integrations/react/use-journey-step.ts +31 -0
  185. package/src/integrations/request-key.ts +18 -10
  186. package/src/integrations/soft-skip.ts +35 -0
  187. package/src/sinks/console.ts +21 -0
  188. package/src/sinks/datadog.ts +52 -33
  189. package/dist/__mocks__/test-runtime.d.ts.map +0 -1
  190. package/dist/__tests__/ambient.test.d.ts.map +0 -1
  191. package/dist/__tests__/axios.test.d.ts.map +0 -1
  192. package/dist/__tests__/context.test.d.ts.map +0 -1
  193. package/dist/__tests__/datadog.test.d.ts.map +0 -1
  194. package/dist/__tests__/define-journey.test.d.ts.map +0 -1
  195. package/dist/__tests__/expose-app-journey.test.d.ts.map +0 -1
  196. package/dist/__tests__/fetch.test.d.ts.map +0 -1
  197. package/dist/__tests__/jquery.test.d.ts.map +0 -1
  198. package/dist/__tests__/registry.test.d.ts +0 -2
  199. package/dist/__tests__/registry.test.d.ts.map +0 -1
  200. package/dist/__tests__/request-key.test.d.ts.map +0 -1
  201. package/dist/__tests__/requests.test.d.ts.map +0 -1
  202. package/dist/__tests__/runtime.test.d.ts.map +0 -1
  203. package/dist/__tests__/scope.test.d.ts.map +0 -1
  204. package/dist/__tests__/sinks.test.d.ts.map +0 -1
  205. package/dist/__tests__/step.test.d.ts.map +0 -1
  206. package/dist/__tests__/timeouts.test.d.ts.map +0 -1
  207. package/dist/core/registry.d.ts +0 -50
  208. package/dist/core/registry.d.ts.map +0 -1
  209. package/dist/core/registry.js +0 -102
  210. package/dist/core/registry.js.map +0 -1
  211. package/dist/endpoint-policy.d.ts.map +0 -1
  212. package/dist/endpoint-policy.js +0 -39
  213. package/dist/endpoint-policy.js.map +0 -1
  214. package/src/__tests__/axios.test.ts +0 -365
  215. package/src/__tests__/jquery.test.ts +0 -327
  216. package/src/__tests__/scope.test.tsx +0 -128
  217. package/src/core/registry.ts +0 -162
  218. /package/dist/{__mocks__ → __test-utils__}/test-runtime.d.ts +0 -0
  219. /package/dist/__tests__/{ambient.test.d.ts → core/ambient.test.d.ts} +0 -0
  220. /package/dist/__tests__/{define-journey.test.d.ts → core/define-journey.test.d.ts} +0 -0
  221. /package/dist/__tests__/{requests.test.d.ts → core/requests.test.d.ts} +0 -0
  222. /package/dist/__tests__/{runtime.test.d.ts → core/runtime.test.d.ts} +0 -0
  223. /package/dist/__tests__/{step.test.d.ts → core/step.test.d.ts} +0 -0
  224. /package/dist/__tests__/{timeouts.test.d.ts → core/timeouts.test.d.ts} +0 -0
  225. /package/dist/__tests__/{axios.test.d.ts → integrations/axios.test.d.ts} +0 -0
  226. /package/dist/__tests__/{context.test.d.ts → integrations/context.test.d.ts} +0 -0
  227. /package/dist/__tests__/{expose-app-journey.test.d.ts → integrations/expose-app-journey.test.d.ts} +0 -0
  228. /package/dist/__tests__/{fetch.test.d.ts → integrations/fetch.test.d.ts} +0 -0
  229. /package/dist/__tests__/{jquery.test.d.ts → integrations/jquery.test.d.ts} +0 -0
  230. /package/dist/__tests__/{request-key.test.d.ts → integrations/request-key.test.d.ts} +0 -0
  231. /package/dist/__tests__/{scope.test.d.ts → integrations/scope.test.d.ts} +0 -0
  232. /package/dist/__tests__/{datadog.test.d.ts → sinks/datadog.test.d.ts} +0 -0
  233. /package/dist/__tests__/{sinks.test.d.ts → sinks/sinks.test.d.ts} +0 -0
@@ -0,0 +1,122 @@
1
+ import { moduleRuntime, resolveJourneyEngine } from './runtime';
2
+ import { adoptJourneyStepStamp, JourneyStepStamp } from './step-tag';
3
+ let ambientStamp = null;
4
+ let ambientStep = null;
5
+ /**
6
+ * Unique in-flight step as a stamp-ready {@link JourneyStepStamp}, or null when
7
+ * auto-attribute is disabled, or when 0 or 2+ steps are in flight app-wide.
8
+ * Ambient stamps never carry `score` or `ignore`. Untagged traffic is attributed
9
+ * to that lone step even if unrelated — prefer `step.stamp()` when the page has
10
+ * background instrumented requests. Disable via
11
+ * `configureJourney({ autoAttributeRequests: false })`.
12
+ */ export function singleInFlightJourneyStep() {
13
+ if (ambientStep === null || ambientStep === void 0 ? void 0 : ambientStep.journey.closed) {
14
+ ambientStep = null;
15
+ ambientStamp = null;
16
+ }
17
+ const activeStep = moduleRuntime.activeJourneyStep();
18
+ if (!activeStep) {
19
+ ambientStamp = null;
20
+ ambientStep = null;
21
+ return null;
22
+ }
23
+ if (ambientStep === activeStep && ambientStamp) {
24
+ return ambientStamp;
25
+ }
26
+ ambientStep = activeStep;
27
+ ambientStamp = new JourneyStepStamp(activeStep);
28
+ return ambientStamp;
29
+ }
30
+ /** @internal Clear cached ambient stamp when runtime state changes. */ export function invalidateAmbientStamp(step) {
31
+ if (!step || step === ambientStep) {
32
+ ambientStamp = null;
33
+ ambientStep = null;
34
+ }
35
+ }
36
+ /**
37
+ * Prefer an explicit `step.stamp()` value; else the ambient in-flight stamp.
38
+ * Same-realm stamps are returned as-is (identity + score + ignore). Branded
39
+ * foreign copies are adopted into a local stamp. Raw StepRecords are not stamps.
40
+ */ export function resolveStamp(explicit) {
41
+ var _singleInFlightJourneyStep;
42
+ const fromExplicit = adoptJourneyStepStamp(explicit);
43
+ if (fromExplicit) {
44
+ return fromExplicit;
45
+ }
46
+ return (_singleInFlightJourneyStep = singleInFlightJourneyStep()) !== null && _singleInFlightJourneyStep !== void 0 ? _singleInFlightJourneyStep : undefined;
47
+ }
48
+ /**
49
+ * Record a finished backend request against a captured step.
50
+ * 5xx / network / slow (over threshold) mark Bad; 4xx is not counted. Fail-fast on breach.
51
+ * @internal Prefer {@link onHttpComplete} from adapters.
52
+ */ export function reportBackendRequest(step, status, durationMs, requestKey) {
53
+ if (!(step === null || step === void 0 ? void 0 : step.journey)) {
54
+ return;
55
+ }
56
+ resolveJourneyEngine(step.journey).reportBackendRequest(step, status, durationMs, requestKey);
57
+ }
58
+ /**
59
+ * Run one step of a named journey. Runs untraced (noop handle) when no matching journey is open.
60
+ * `journey` may be a name, null, an ordered candidate list, a def, or a handle.
61
+ * A def or handle auto-starts when that journey is not already open; a bare name does not.
62
+ * Prefer `defineJourney(...).step` when you own the journey config.
63
+ */ export async function journeyStep(journey, stepName, fn, opts) {
64
+ return moduleRuntime.journeyStep(journey, stepName, fn, opts);
65
+ }
66
+ /** Merge custom tags onto an open journey. No-op if not open. Prefer `handle.setTags`. */ export function setJourneyTags(name, tags) {
67
+ moduleRuntime.setJourneyTags(name, tags);
68
+ }
69
+ /** Mark a named journey Bad for a custom reason (fail-fast). Prefer `handle.fail`. */ export function failJourney(name, reason) {
70
+ const journey = moduleRuntime.getOpenJourney(name);
71
+ if (journey) {
72
+ moduleRuntime.failJourney(journey, reason);
73
+ }
74
+ }
75
+ /** Successful end. Outcome stays Bad if a breach already occurred. No-op when name is null. Prefer `handle.complete`. */ export function completeJourney(name, tags) {
76
+ moduleRuntime.completeJourney(name, tags);
77
+ }
78
+ /** User left before finishing. Stays Bad if a breach already occurred (breach-anchored). Prefer `handle.exclude`. */ export function excludeJourney(name) {
79
+ const journey = moduleRuntime.getOpenJourney(name);
80
+ if (journey) {
81
+ moduleRuntime.excludeJourney(journey);
82
+ }
83
+ }
84
+ /** Turn a journey config into a handle with bound lifecycle methods. Preferred public API. */ export function defineJourney(config) {
85
+ return {
86
+ config,
87
+ start (tags) {
88
+ moduleRuntime.startJourney(config);
89
+ if (tags) {
90
+ moduleRuntime.setJourneyTags(config.name, tags);
91
+ }
92
+ },
93
+ step (stepName, fn, opts) {
94
+ if (!moduleRuntime.getOpenJourney(config.name)) {
95
+ moduleRuntime.startJourney(config);
96
+ }
97
+ return journeyStep(config.name, stepName, fn, opts);
98
+ },
99
+ async mountStep (stepName, fn, opts) {
100
+ // Defer so a parent <JourneyScope> opens first (child effects run before parent).
101
+ await Promise.resolve();
102
+ if (!moduleRuntime.getOpenJourney(config.name)) {
103
+ moduleRuntime.startJourney(config);
104
+ }
105
+ return journeyStep(config.name, stepName, fn, opts);
106
+ },
107
+ complete (tags) {
108
+ completeJourney(config.name, tags);
109
+ },
110
+ fail (reason) {
111
+ failJourney(config.name, reason);
112
+ },
113
+ exclude () {
114
+ excludeJourney(config.name);
115
+ },
116
+ setTags (tags) {
117
+ setJourneyTags(config.name, tags);
118
+ }
119
+ };
120
+ }
121
+
122
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/api.ts"],"sourcesContent":["import { moduleRuntime, resolveJourneyEngine } from './runtime';\nimport { adoptJourneyStepStamp, JourneyStepStamp } from './step-tag';\nimport type {\n JourneyDef,\n JourneyHandle,\n JourneyStepOptions,\n JourneyStepTarget,\n StepHandle,\n StepRecord,\n TagValue,\n} from './types';\n\nlet ambientStamp: JourneyStepStamp | null = null;\nlet ambientStep: StepRecord | null = null;\n\n/**\n * Unique in-flight step as a stamp-ready {@link JourneyStepStamp}, or null when\n * auto-attribute is disabled, or when 0 or 2+ steps are in flight app-wide.\n * Ambient stamps never carry `score` or `ignore`. Untagged traffic is attributed\n * to that lone step even if unrelated — prefer `step.stamp()` when the page has\n * background instrumented requests. Disable via\n * `configureJourney({ autoAttributeRequests: false })`.\n */\nexport function singleInFlightJourneyStep(): JourneyStepStamp | null {\n if (ambientStep?.journey.closed) {\n ambientStep = null;\n ambientStamp = null;\n }\n const activeStep = moduleRuntime.activeJourneyStep();\n if (!activeStep) {\n ambientStamp = null;\n ambientStep = null;\n return null;\n }\n if (ambientStep === activeStep && ambientStamp) {\n return ambientStamp;\n }\n ambientStep = activeStep;\n ambientStamp = new JourneyStepStamp(activeStep);\n return ambientStamp;\n}\n\n/** @internal Clear cached ambient stamp when runtime state changes. */\nexport function invalidateAmbientStamp(step?: StepRecord): void {\n if (!step || step === ambientStep) {\n ambientStamp = null;\n ambientStep = null;\n }\n}\n\n/**\n * Prefer an explicit `step.stamp()` value; else the ambient in-flight stamp.\n * Same-realm stamps are returned as-is (identity + score + ignore). Branded\n * foreign copies are adopted into a local stamp. Raw StepRecords are not stamps.\n */\nexport function resolveStamp(explicit?: unknown): JourneyStepStamp | undefined {\n const fromExplicit = adoptJourneyStepStamp(explicit);\n if (fromExplicit) {\n return fromExplicit;\n }\n return singleInFlightJourneyStep() ?? undefined;\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 * @internal Prefer {@link onHttpComplete} from adapters.\n */\nexport function reportBackendRequest(\n step: StepRecord | undefined,\n status: number | undefined,\n durationMs: number,\n requestKey: string\n): void {\n if (!step?.journey) {\n return;\n }\n resolveJourneyEngine(step.journey).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, an ordered candidate list, a def, or a handle.\n * A def or handle auto-starts when that journey is not already open; a bare name does not.\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 moduleRuntime.journeyStep(journey, stepName, fn, opts);\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 moduleRuntime.setJourneyTags(name, tags);\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 const journey = moduleRuntime.getOpenJourney(name);\n if (journey) {\n moduleRuntime.failJourney(journey, reason);\n }\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 moduleRuntime.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 const journey = moduleRuntime.getOpenJourney(name);\n if (journey) {\n moduleRuntime.excludeJourney(journey);\n }\n}\n\n/** Turn a journey config into a handle with bound lifecycle methods. Preferred public API. */\nexport function defineJourney(config: JourneyDef): JourneyHandle {\n return {\n config,\n start(tags) {\n moduleRuntime.startJourney(config);\n if (tags) {\n moduleRuntime.setJourneyTags(config.name, tags);\n }\n },\n step(stepName, fn, opts) {\n if (!moduleRuntime.getOpenJourney(config.name)) {\n moduleRuntime.startJourney(config);\n }\n return journeyStep(config.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 if (!moduleRuntime.getOpenJourney(config.name)) {\n moduleRuntime.startJourney(config);\n }\n return journeyStep(config.name, stepName, fn, opts);\n },\n complete(tags) {\n completeJourney(config.name, tags);\n },\n fail(reason) {\n failJourney(config.name, reason);\n },\n exclude() {\n excludeJourney(config.name);\n },\n setTags(tags) {\n setJourneyTags(config.name, tags);\n },\n };\n}\n"],"names":["moduleRuntime","resolveJourneyEngine","adoptJourneyStepStamp","JourneyStepStamp","ambientStamp","ambientStep","singleInFlightJourneyStep","journey","closed","activeStep","activeJourneyStep","invalidateAmbientStamp","step","resolveStamp","explicit","fromExplicit","undefined","reportBackendRequest","status","durationMs","requestKey","journeyStep","stepName","fn","opts","setJourneyTags","name","tags","failJourney","reason","getOpenJourney","completeJourney","excludeJourney","defineJourney","config","start","startJourney","mountStep","Promise","resolve","complete","fail","exclude","setTags"],"mappings":"AAAA,SAASA,aAAa,EAAEC,oBAAoB,QAAQ,YAAY;AAChE,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ,aAAa;AAWrE,IAAIC,eAAwC;AAC5C,IAAIC,cAAiC;AAErC;;;;;;;CAOC,GACD,OAAO,SAASC;IACZ,IAAID,wBAAAA,kCAAAA,YAAaE,OAAO,CAACC,MAAM,EAAE;QAC7BH,cAAc;QACdD,eAAe;IACnB;IACA,MAAMK,aAAaT,cAAcU,iBAAiB;IAClD,IAAI,CAACD,YAAY;QACbL,eAAe;QACfC,cAAc;QACd,OAAO;IACX;IACA,IAAIA,gBAAgBI,cAAcL,cAAc;QAC5C,OAAOA;IACX;IACAC,cAAcI;IACdL,eAAe,IAAID,iBAAiBM;IACpC,OAAOL;AACX;AAEA,qEAAqE,GACrE,OAAO,SAASO,uBAAuBC,IAAiB;IACpD,IAAI,CAACA,QAAQA,SAASP,aAAa;QAC/BD,eAAe;QACfC,cAAc;IAClB;AACJ;AAEA;;;;CAIC,GACD,OAAO,SAASQ,aAAaC,QAAkB;QAKpCR;IAJP,MAAMS,eAAeb,sBAAsBY;IAC3C,IAAIC,cAAc;QACd,OAAOA;IACX;IACA,QAAOT,6BAAAA,yCAAAA,wCAAAA,6BAA+BU;AAC1C;AAEA;;;;CAIC,GACD,OAAO,SAASC,qBACZL,IAA4B,EAC5BM,MAA0B,EAC1BC,UAAkB,EAClBC,UAAkB;IAElB,IAAI,EAACR,iBAAAA,2BAAAA,KAAML,OAAO,GAAE;QAChB;IACJ;IACAN,qBAAqBW,KAAKL,OAAO,EAAEU,oBAAoB,CAACL,MAAMM,QAAQC,YAAYC;AACtF;AAEA;;;;;CAKC,GACD,OAAO,eAAeC,YAClBd,OAA0B,EAC1Be,QAAgB,EAChBC,EAAwC,EACxCC,IAAyB;IAEzB,OAAOxB,cAAcqB,WAAW,CAACd,SAASe,UAAUC,IAAIC;AAC5D;AAEA,wFAAwF,GACxF,OAAO,SAASC,eAAeC,IAAmB,EAAEC,IAA8B;IAC9E3B,cAAcyB,cAAc,CAACC,MAAMC;AACvC;AAEA,oFAAoF,GACpF,OAAO,SAASC,YAAYF,IAAY,EAAEG,MAAc;IACpD,MAAMtB,UAAUP,cAAc8B,cAAc,CAACJ;IAC7C,IAAInB,SAAS;QACTP,cAAc4B,WAAW,CAACrB,SAASsB;IACvC;AACJ;AAEA,uHAAuH,GACvH,OAAO,SAASE,gBAAgBL,IAAmB,EAAEC,IAA+B;IAChF3B,cAAc+B,eAAe,CAACL,MAAMC;AACxC;AAEA,mHAAmH,GACnH,OAAO,SAASK,eAAeN,IAAY;IACvC,MAAMnB,UAAUP,cAAc8B,cAAc,CAACJ;IAC7C,IAAInB,SAAS;QACTP,cAAcgC,cAAc,CAACzB;IACjC;AACJ;AAEA,4FAA4F,GAC5F,OAAO,SAAS0B,cAAcC,MAAkB;IAC5C,OAAO;QACHA;QACAC,OAAMR,IAAI;YACN3B,cAAcoC,YAAY,CAACF;YAC3B,IAAIP,MAAM;gBACN3B,cAAcyB,cAAc,CAACS,OAAOR,IAAI,EAAEC;YAC9C;QACJ;QACAf,MAAKU,QAAQ,EAAEC,EAAE,EAAEC,IAAI;YACnB,IAAI,CAACxB,cAAc8B,cAAc,CAACI,OAAOR,IAAI,GAAG;gBAC5C1B,cAAcoC,YAAY,CAACF;YAC/B;YACA,OAAOb,YAAYa,OAAOR,IAAI,EAAEJ,UAAUC,IAAIC;QAClD;QACA,MAAMa,WAAUf,QAAQ,EAAEC,EAAE,EAAEC,IAAI;YAC9B,kFAAkF;YAClF,MAAMc,QAAQC,OAAO;YACrB,IAAI,CAACvC,cAAc8B,cAAc,CAACI,OAAOR,IAAI,GAAG;gBAC5C1B,cAAcoC,YAAY,CAACF;YAC/B;YACA,OAAOb,YAAYa,OAAOR,IAAI,EAAEJ,UAAUC,IAAIC;QAClD;QACAgB,UAASb,IAAI;YACTI,gBAAgBG,OAAOR,IAAI,EAAEC;QACjC;QACAc,MAAKZ,MAAM;YACPD,YAAYM,OAAOR,IAAI,EAAEG;QAC7B;QACAa;YACIV,eAAeE,OAAOR,IAAI;QAC9B;QACAiB,SAAQhB,IAAI;YACRF,eAAeS,OAAOR,IAAI,EAAEC;QAChC;IACJ;AACJ"}
@@ -1,3 +1,4 @@
1
+ import type { JourneyState } from './types';
1
2
  /** Per-endpoint request policy (app-wide or per-journey). Longest matching prefix wins. */
2
3
  export interface EndpointPolicy {
3
4
  /**
@@ -7,18 +8,22 @@ export interface EndpointPolicy {
7
8
  * `match` already supplies the boundary.
8
9
  */
9
10
  match: string;
10
- /** Custom slow-request threshold in ms; omit / 0 falls through. */
11
- timeoutMs?: number;
12
- /** When true, errors and slow responses never mark the journey Bad. */
11
+ /** Custom slow-request threshold in ms; omit to fall through. `0` disables latency scoring for this prefix. */
12
+ slowRequestMs?: number;
13
+ /** When true, this endpoint never changes the journey verdict (errors, latency, aborts, 4xx). */
13
14
  ignore?: boolean;
14
15
  }
15
16
  /** App-wide slow-request threshold fallback (not an axios abort). */
16
- export interface AppRequestTimeouts {
17
+ export interface SlowRequestConfig {
17
18
  /** Fallback threshold when no endpoint or journey override applies. */
18
19
  defaultMs: number;
19
20
  /** App-wide endpoint overrides; journey-specific ones belong on JourneyDef.endpoints. */
20
21
  endpoints?: readonly EndpointPolicy[];
21
22
  }
23
+ export interface ResolvedEndpointPolicy {
24
+ ignore: boolean;
25
+ slowRequestMs: number;
26
+ }
22
27
  /** Copy sorted longest-match-first so lookup can return on the first hit. */
23
28
  export declare function sortEndpointsByLongestMatch(endpoints: readonly EndpointPolicy[] | undefined): EndpointPolicy[] | undefined;
24
29
  /**
@@ -26,4 +31,9 @@ export declare function sortEndpointsByLongestMatch(endpoints: readonly Endpoint
26
31
  * Expects `endpoints` sorted longest-match-first (see `sortEndpointsByLongestMatch`).
27
32
  */
28
33
  export declare function longestEndpointMatch(endpoints: readonly EndpointPolicy[] | undefined, key: string): EndpointPolicy | undefined;
34
+ /**
35
+ * Resolve ignore + latency threshold with longest-prefix matching.
36
+ * Journey overrides win over app defaults for slow thresholds.
37
+ */
38
+ export declare function resolveEndpointPolicy(journey: JourneyState, appSlow: SlowRequestConfig, requestKey: string): ResolvedEndpointPolicy;
29
39
  //# sourceMappingURL=endpoint-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-policy.d.ts","sourceRoot":"","sources":["../../src/core/endpoint-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,2FAA2F;AAC3F,MAAM,WAAW,cAAc;IAC3B;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,+GAA+G;IAC/G,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iGAAiG;IACjG,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAC9B,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,yFAAyF;IACzF,SAAS,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;CACzC;AAED,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,6EAA6E;AAC7E,wBAAgB,2BAA2B,CACvC,SAAS,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,GACjD,cAAc,EAAE,GAAG,SAAS,CAQ9B;AAiBD;;;GAGG;AACH,wBAAgB,oBAAoB,CAChC,SAAS,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,EAChD,GAAG,EAAE,MAAM,GACZ,cAAc,GAAG,SAAS,CAO5B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACjC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,iBAAiB,EAC1B,UAAU,EAAE,MAAM,GACnB,sBAAsB,CAyBxB"}
@@ -0,0 +1,70 @@
1
+ /** Copy sorted longest-match-first so lookup can return on the first hit. */ export function sortEndpointsByLongestMatch(endpoints) {
2
+ if (endpoints == null) {
3
+ return undefined;
4
+ }
5
+ if (endpoints.length <= 1) {
6
+ return endpoints.length === 0 ? [] : [
7
+ ...endpoints
8
+ ];
9
+ }
10
+ return [
11
+ ...endpoints
12
+ ].sort((a, b)=>b.match.length - a.match.length);
13
+ }
14
+ /**
15
+ * True when `key` equals `match` or continues past a path boundary.
16
+ * `/api/user` matches `/api/user` and `/api/user/42`, not `/api/user-preferences`.
17
+ */ function matchesEndpoint(key, match) {
18
+ if (!key.startsWith(match)) {
19
+ return false;
20
+ }
21
+ if (match.endsWith('/')) {
22
+ return true;
23
+ }
24
+ const next = key[match.length];
25
+ return next === undefined || next === '/';
26
+ }
27
+ /**
28
+ * Longest-prefix match of an endpoint list against a request key.
29
+ * Expects `endpoints` sorted longest-match-first (see `sortEndpointsByLongestMatch`).
30
+ */ export function longestEndpointMatch(endpoints, key) {
31
+ for (const e of endpoints !== null && endpoints !== void 0 ? endpoints : []){
32
+ if (matchesEndpoint(key, e.match)) {
33
+ return e;
34
+ }
35
+ }
36
+ return undefined;
37
+ }
38
+ /**
39
+ * Resolve ignore + latency threshold with longest-prefix matching.
40
+ * Journey overrides win over app defaults for slow thresholds.
41
+ */ export function resolveEndpointPolicy(journey, appSlow, requestKey) {
42
+ var _ref, _ref1;
43
+ const own = longestEndpointMatch(journey.endpoints, requestKey);
44
+ if ((own === null || own === void 0 ? void 0 : own.ignore) === true) {
45
+ return {
46
+ ignore: true,
47
+ slowRequestMs: 0
48
+ };
49
+ }
50
+ const app = longestEndpointMatch(appSlow.endpoints, requestKey);
51
+ if (own) {
52
+ var _ref2, _ref3, _own_slowRequestMs;
53
+ return {
54
+ ignore: false,
55
+ slowRequestMs: (_ref2 = (_ref3 = (_own_slowRequestMs = own.slowRequestMs) !== null && _own_slowRequestMs !== void 0 ? _own_slowRequestMs : app === null || app === void 0 ? void 0 : app.slowRequestMs) !== null && _ref3 !== void 0 ? _ref3 : journey.slowRequestMs) !== null && _ref2 !== void 0 ? _ref2 : appSlow.defaultMs
56
+ };
57
+ }
58
+ if ((app === null || app === void 0 ? void 0 : app.ignore) === true) {
59
+ return {
60
+ ignore: true,
61
+ slowRequestMs: 0
62
+ };
63
+ }
64
+ return {
65
+ ignore: false,
66
+ slowRequestMs: (_ref = (_ref1 = app === null || app === void 0 ? void 0 : app.slowRequestMs) !== null && _ref1 !== void 0 ? _ref1 : journey.slowRequestMs) !== null && _ref !== void 0 ? _ref : appSlow.defaultMs
67
+ };
68
+ }
69
+
70
+ //# sourceMappingURL=endpoint-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/endpoint-policy.ts"],"sourcesContent":["import type { JourneyState } from './types';\n\n/** Per-endpoint request policy (app-wide or per-journey). Longest matching prefix wins. */\nexport interface EndpointPolicy {\n /**\n * Path/host prefix against the request key (`\"/path\"` same-origin, `\"host/path\"` cross-domain).\n * Match requires an exact hit or a `/` boundary after the prefix — `/api/user` matches\n * `/api/user` and `/api/user/42`, but not `/api/user-preferences`. A trailing `/` on\n * `match` already supplies the boundary.\n */\n match: string;\n /** Custom slow-request threshold in ms; omit to fall through. `0` disables latency scoring for this prefix. */\n slowRequestMs?: number;\n /** When true, this endpoint never changes the journey verdict (errors, latency, aborts, 4xx). */\n ignore?: boolean;\n}\n\n/** App-wide slow-request threshold fallback (not an axios abort). */\nexport interface SlowRequestConfig {\n /** Fallback threshold when no endpoint or journey override applies. */\n defaultMs: number;\n /** App-wide endpoint overrides; journey-specific ones belong on JourneyDef.endpoints. */\n endpoints?: readonly EndpointPolicy[];\n}\n\nexport interface ResolvedEndpointPolicy {\n ignore: boolean;\n slowRequestMs: number;\n}\n\n/** Copy sorted longest-match-first so lookup can return on the first hit. */\nexport function sortEndpointsByLongestMatch(\n endpoints: readonly EndpointPolicy[] | undefined\n): EndpointPolicy[] | undefined {\n if (endpoints == null) {\n return undefined;\n }\n if (endpoints.length <= 1) {\n return endpoints.length === 0 ? [] : [...endpoints];\n }\n return [...endpoints].sort((a, b) => b.match.length - a.match.length);\n}\n\n/**\n * True when `key` equals `match` or continues past a path boundary.\n * `/api/user` matches `/api/user` and `/api/user/42`, not `/api/user-preferences`.\n */\nfunction matchesEndpoint(key: string, match: string): boolean {\n if (!key.startsWith(match)) {\n return false;\n }\n if (match.endsWith('/')) {\n return true;\n }\n const next = key[match.length];\n return next === undefined || next === '/';\n}\n\n/**\n * Longest-prefix match of an endpoint list against a request key.\n * Expects `endpoints` sorted longest-match-first (see `sortEndpointsByLongestMatch`).\n */\nexport function longestEndpointMatch(\n endpoints: readonly EndpointPolicy[] | undefined,\n key: string\n): EndpointPolicy | undefined {\n for (const e of endpoints ?? []) {\n if (matchesEndpoint(key, e.match)) {\n return e;\n }\n }\n return undefined;\n}\n\n/**\n * Resolve ignore + latency threshold with longest-prefix matching.\n * Journey overrides win over app defaults for slow thresholds.\n */\nexport function resolveEndpointPolicy(\n journey: JourneyState,\n appSlow: SlowRequestConfig,\n requestKey: string\n): ResolvedEndpointPolicy {\n const own = longestEndpointMatch(journey.endpoints, requestKey);\n if (own?.ignore === true) {\n return { ignore: true, slowRequestMs: 0 };\n }\n\n const app = longestEndpointMatch(appSlow.endpoints, requestKey);\n if (own) {\n return {\n ignore: false,\n slowRequestMs:\n own.slowRequestMs ??\n app?.slowRequestMs ??\n journey.slowRequestMs ??\n appSlow.defaultMs,\n };\n }\n if (app?.ignore === true) {\n return { ignore: true, slowRequestMs: 0 };\n }\n\n return {\n ignore: false,\n slowRequestMs: app?.slowRequestMs ?? journey.slowRequestMs ?? appSlow.defaultMs,\n };\n}\n"],"names":["sortEndpointsByLongestMatch","endpoints","undefined","length","sort","a","b","match","matchesEndpoint","key","startsWith","endsWith","next","longestEndpointMatch","e","resolveEndpointPolicy","journey","appSlow","requestKey","app","own","ignore","slowRequestMs","defaultMs"],"mappings":"AA8BA,2EAA2E,GAC3E,OAAO,SAASA,4BACZC,SAAgD;IAEhD,IAAIA,aAAa,MAAM;QACnB,OAAOC;IACX;IACA,IAAID,UAAUE,MAAM,IAAI,GAAG;QACvB,OAAOF,UAAUE,MAAM,KAAK,IAAI,EAAE,GAAG;eAAIF;SAAU;IACvD;IACA,OAAO;WAAIA;KAAU,CAACG,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAEC,KAAK,CAACJ,MAAM,GAAGE,EAAEE,KAAK,CAACJ,MAAM;AACxE;AAEA;;;CAGC,GACD,SAASK,gBAAgBC,GAAW,EAAEF,KAAa;IAC/C,IAAI,CAACE,IAAIC,UAAU,CAACH,QAAQ;QACxB,OAAO;IACX;IACA,IAAIA,MAAMI,QAAQ,CAAC,MAAM;QACrB,OAAO;IACX;IACA,MAAMC,OAAOH,GAAG,CAACF,MAAMJ,MAAM,CAAC;IAC9B,OAAOS,SAASV,aAAaU,SAAS;AAC1C;AAEA;;;CAGC,GACD,OAAO,SAASC,qBACZZ,SAAgD,EAChDQ,GAAW;IAEX,KAAK,MAAMK,KAAKb,sBAAAA,uBAAAA,YAAa,EAAE,CAAE;QAC7B,IAAIO,gBAAgBC,KAAKK,EAAEP,KAAK,GAAG;YAC/B,OAAOO;QACX;IACJ;IACA,OAAOZ;AACX;AAEA;;;CAGC,GACD,OAAO,SAASa,sBACZC,OAAqB,EACrBC,OAA0B,EAC1BC,UAAkB;QAwBCC;IAtBnB,MAAMC,MAAMP,qBAAqBG,QAAQf,SAAS,EAAEiB;IACpD,IAAIE,CAAAA,gBAAAA,0BAAAA,IAAKC,MAAM,MAAK,MAAM;QACtB,OAAO;YAAEA,QAAQ;YAAMC,eAAe;QAAE;IAC5C;IAEA,MAAMH,MAAMN,qBAAqBI,QAAQhB,SAAS,EAAEiB;IACpD,IAAIE,KAAK;YAIGA,OAAAA,OAAAA;QAHR,OAAO;YACHC,QAAQ;YACRC,aAAa,GACTF,SAAAA,SAAAA,qBAAAA,IAAIE,aAAa,cAAjBF,gCAAAA,qBACAD,gBAAAA,0BAAAA,IAAKG,aAAa,cADlBF,mBAAAA,QAEAJ,QAAQM,aAAa,cAFrBF,mBAAAA,QAGAH,QAAQM,SAAS;QACzB;IACJ;IACA,IAAIJ,CAAAA,gBAAAA,0BAAAA,IAAKE,MAAM,MAAK,MAAM;QACtB,OAAO;YAAEA,QAAQ;YAAMC,eAAe;QAAE;IAC5C;IAEA,OAAO;QACHD,QAAQ;QACRC,aAAa,GAAEH,gBAAAA,gBAAAA,0BAAAA,IAAKG,aAAa,yCAAIN,QAAQM,aAAa,cAA3CH,kBAAAA,OAA+CF,QAAQM,SAAS;IACnF;AACJ"}
@@ -1,6 +1,7 @@
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';
1
+ /** Core barrel — public free helpers, handles, and types. Engine lives in `./runtime`. */
2
+ export { completeJourney, defineJourney, excludeJourney, failJourney, journeyStep, reportBackendRequest, resolveStamp, setJourneyTags, singleInFlightJourneyStep, } from './api';
3
+ export { resetJourney, } from './runtime';
4
+ export type { JourneyDef, JourneyEvent, JourneyHandle, JourneyNameLike, JourneySink, JourneyStepEvent, JourneyStepOptions, JourneyStepTarget, StepHandle, TagValue, } from './types';
5
+ export { JourneyStepStamp } from './step-tag';
6
+ export type { JourneyHttpPolicyContext, JourneyHttpScore, JourneyHttpScoreContext, JourneyRequestPolicy, JourneyStampOptions, RequestPolicyConfig, } from './request-policy';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACd,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,yBAAyB,GAC5B,MAAM,OAAO,CAAC;AACf,OAAO,EAEH,YAAY,GACf,MAAM,WAAW,CAAC;AACnB,YAAY,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,QAAQ,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EACR,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACtB,MAAM,kBAAkB,CAAC"}
@@ -1,5 +1,6 @@
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';
1
+ /** Core barrel — public free helpers, handles, and types. Engine lives in `./runtime`. */ export { completeJourney, defineJourney, excludeJourney, failJourney, journeyStep, reportBackendRequest, resolveStamp, setJourneyTags, singleInFlightJourneyStep } from './api';
2
+ export { // @internal Test helper not a supported consumer API.
3
+ resetJourney } from './runtime';
4
+ export { JourneyStepStamp } from './step-tag';
4
5
 
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +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"}
1
+ {"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["/** Core barrel — public free helpers, handles, and types. Engine lives in `./runtime`. */\n\nexport {\n completeJourney,\n defineJourney,\n excludeJourney,\n failJourney,\n journeyStep,\n reportBackendRequest,\n resolveStamp,\n setJourneyTags,\n singleInFlightJourneyStep,\n} from './api';\nexport {\n // @internal Test helper — not a supported consumer API.\n resetJourney,\n} from './runtime';\nexport type {\n JourneyDef,\n JourneyEvent,\n JourneyHandle,\n JourneyNameLike,\n JourneySink,\n JourneyStepEvent,\n JourneyStepOptions,\n JourneyStepTarget,\n StepHandle,\n TagValue,\n} from './types';\nexport { JourneyStepStamp } from './step-tag';\nexport type {\n JourneyHttpPolicyContext,\n JourneyHttpScore,\n JourneyHttpScoreContext,\n JourneyRequestPolicy,\n JourneyStampOptions,\n RequestPolicyConfig,\n} from './request-policy';\n"],"names":["completeJourney","defineJourney","excludeJourney","failJourney","journeyStep","reportBackendRequest","resolveStamp","setJourneyTags","singleInFlightJourneyStep","resetJourney","JourneyStepStamp"],"mappings":"AAAA,wFAAwF,GAExF,SACIA,eAAe,EACfC,aAAa,EACbC,cAAc,EACdC,WAAW,EACXC,WAAW,EACXC,oBAAoB,EACpBC,YAAY,EACZC,cAAc,EACdC,yBAAyB,QACtB,QAAQ;AACf,SACI,wDAAwD;AACxDC,YAAY,QACT,YAAY;AAanB,SAASC,gBAAgB,QAAQ,aAAa"}
@@ -0,0 +1,29 @@
1
+ /** Payload / timer bounds shared by the engine and default sinks. */
2
+ export declare const DEFAULT_MAX_STEPS = 50;
3
+ export declare const MAX_STEPS_CAP = 200;
4
+ export declare const MAX_TAG_KEYS = 32;
5
+ export declare const MAX_ATTRIBUTE_KEYS = 64;
6
+ export declare const MAX_ATTRIBUTED_REQUEST_KEYS = 50;
7
+ export declare const MAX_TAG_VALUE_LEN = 200;
8
+ export declare const DEFAULT_JOURNEY_IDLE_MS: number;
9
+ /** True for prototype-polluting keys and a small secret-name deny-list (case-insensitive). */
10
+ export declare function isUnsafeKey(key: string): boolean;
11
+ /**
12
+ * Finite integer ≥ 1, else `fallback`. Used for maxSteps-like caps.
13
+ * Non-finite / ≤ 0 / non-numbers return `fallback`.
14
+ */
15
+ export declare function finitePositiveInt(n: unknown, fallback: number): number;
16
+ /**
17
+ * Journey/step timeout: finite ≥ 0 keeps the value (floored); anything else is 0 (disabled).
18
+ */
19
+ export declare function finiteTimeoutMs(n: unknown): number;
20
+ /** Clamp recorded-step cap to 1..MAX_STEPS_CAP; invalid → DEFAULT_MAX_STEPS. */
21
+ export declare function clampMaxSteps(n: unknown): number;
22
+ /** Finite ≥ 0 slow-request threshold, or undefined to fall through. */
23
+ export declare function finiteSlowRequestMs(n: unknown): number | undefined;
24
+ /** Explicit 0 disables; omitted uses idle default; finite N keeps caller timeout. */
25
+ export declare function resolveJourneyTimeoutMs(timeoutMs: number | undefined, idleDefaultMs?: number): {
26
+ ms: number;
27
+ explicit: boolean;
28
+ };
29
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/core/limits.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAErE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,aAAa,MAAM,CAAC;AACjC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,uBAAuB,QAAkB,CAAC;AAevD,8FAA8F;AAC9F,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKtE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAKlD;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAGhD;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKlE;AAED,qFAAqF;AACrF,wBAAgB,uBAAuB,CACnC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,aAAa,GAAE,MAAgC,GAChD;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAKnC"}
@@ -0,0 +1,63 @@
1
+ /** Payload / timer bounds shared by the engine and default sinks. */ export const DEFAULT_MAX_STEPS = 50;
2
+ export const MAX_STEPS_CAP = 200;
3
+ export const MAX_TAG_KEYS = 32;
4
+ export const MAX_ATTRIBUTE_KEYS = 64;
5
+ export const MAX_ATTRIBUTED_REQUEST_KEYS = 50;
6
+ export const MAX_TAG_VALUE_LEN = 200;
7
+ export const DEFAULT_JOURNEY_IDLE_MS = 15 * 60 * 1000;
8
+ const DENIED_KEYS = new Set([
9
+ '__proto__',
10
+ 'constructor',
11
+ 'prototype',
12
+ 'authorization',
13
+ 'cookie',
14
+ 'set-cookie',
15
+ 'password',
16
+ 'token',
17
+ 'secret',
18
+ 'ssn'
19
+ ]);
20
+ /** True for prototype-polluting keys and a small secret-name deny-list (case-insensitive). */ export function isUnsafeKey(key) {
21
+ return DENIED_KEYS.has(key.toLowerCase());
22
+ }
23
+ /**
24
+ * Finite integer ≥ 1, else `fallback`. Used for maxSteps-like caps.
25
+ * Non-finite / ≤ 0 / non-numbers return `fallback`.
26
+ */ export function finitePositiveInt(n, fallback) {
27
+ if (typeof n !== 'number' || !Number.isFinite(n) || n <= 0) {
28
+ return fallback;
29
+ }
30
+ return Math.floor(n);
31
+ }
32
+ /**
33
+ * Journey/step timeout: finite ≥ 0 keeps the value (floored); anything else is 0 (disabled).
34
+ */ export function finiteTimeoutMs(n) {
35
+ if (typeof n !== 'number' || !Number.isFinite(n) || n < 0) {
36
+ return 0;
37
+ }
38
+ return Math.floor(n);
39
+ }
40
+ /** Clamp recorded-step cap to 1..MAX_STEPS_CAP; invalid → DEFAULT_MAX_STEPS. */ export function clampMaxSteps(n) {
41
+ const value = finitePositiveInt(n, DEFAULT_MAX_STEPS);
42
+ return Math.min(value, MAX_STEPS_CAP);
43
+ }
44
+ /** Finite ≥ 0 slow-request threshold, or undefined to fall through. */ export function finiteSlowRequestMs(n) {
45
+ if (typeof n !== 'number' || !Number.isFinite(n) || n < 0) {
46
+ return undefined;
47
+ }
48
+ return Math.floor(n);
49
+ }
50
+ /** Explicit 0 disables; omitted uses idle default; finite N keeps caller timeout. */ export function resolveJourneyTimeoutMs(timeoutMs, idleDefaultMs = DEFAULT_JOURNEY_IDLE_MS) {
51
+ if (timeoutMs === undefined) {
52
+ return {
53
+ ms: finiteTimeoutMs(idleDefaultMs),
54
+ explicit: false
55
+ };
56
+ }
57
+ return {
58
+ ms: finiteTimeoutMs(timeoutMs),
59
+ explicit: true
60
+ };
61
+ }
62
+
63
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/limits.ts"],"sourcesContent":["/** Payload / timer bounds shared by the engine and default sinks. */\n\nexport const DEFAULT_MAX_STEPS = 50;\nexport const MAX_STEPS_CAP = 200;\nexport const MAX_TAG_KEYS = 32;\nexport const MAX_ATTRIBUTE_KEYS = 64;\nexport const MAX_ATTRIBUTED_REQUEST_KEYS = 50;\nexport const MAX_TAG_VALUE_LEN = 200;\nexport const DEFAULT_JOURNEY_IDLE_MS = 15 * 60 * 1_000;\n\nconst DENIED_KEYS = new Set([\n '__proto__',\n 'constructor',\n 'prototype',\n 'authorization',\n 'cookie',\n 'set-cookie',\n 'password',\n 'token',\n 'secret',\n 'ssn',\n]);\n\n/** True for prototype-polluting keys and a small secret-name deny-list (case-insensitive). */\nexport function isUnsafeKey(key: string): boolean {\n return DENIED_KEYS.has(key.toLowerCase());\n}\n\n/**\n * Finite integer ≥ 1, else `fallback`. Used for maxSteps-like caps.\n * Non-finite / ≤ 0 / non-numbers return `fallback`.\n */\nexport function finitePositiveInt(n: unknown, fallback: number): number {\n if (typeof n !== 'number' || !Number.isFinite(n) || n <= 0) {\n return fallback;\n }\n return Math.floor(n);\n}\n\n/**\n * Journey/step timeout: finite ≥ 0 keeps the value (floored); anything else is 0 (disabled).\n */\nexport function finiteTimeoutMs(n: unknown): number {\n if (typeof n !== 'number' || !Number.isFinite(n) || n < 0) {\n return 0;\n }\n return Math.floor(n);\n}\n\n/** Clamp recorded-step cap to 1..MAX_STEPS_CAP; invalid → DEFAULT_MAX_STEPS. */\nexport function clampMaxSteps(n: unknown): number {\n const value = finitePositiveInt(n, DEFAULT_MAX_STEPS);\n return Math.min(value, MAX_STEPS_CAP);\n}\n\n/** Finite ≥ 0 slow-request threshold, or undefined to fall through. */\nexport function finiteSlowRequestMs(n: unknown): number | undefined {\n if (typeof n !== 'number' || !Number.isFinite(n) || n < 0) {\n return undefined;\n }\n return Math.floor(n);\n}\n\n/** Explicit 0 disables; omitted uses idle default; finite N keeps caller timeout. */\nexport function resolveJourneyTimeoutMs(\n timeoutMs: number | undefined,\n idleDefaultMs: number = DEFAULT_JOURNEY_IDLE_MS\n): { ms: number; explicit: boolean } {\n if (timeoutMs === undefined) {\n return { ms: finiteTimeoutMs(idleDefaultMs), explicit: false };\n }\n return { ms: finiteTimeoutMs(timeoutMs), explicit: true };\n}\n"],"names":["DEFAULT_MAX_STEPS","MAX_STEPS_CAP","MAX_TAG_KEYS","MAX_ATTRIBUTE_KEYS","MAX_ATTRIBUTED_REQUEST_KEYS","MAX_TAG_VALUE_LEN","DEFAULT_JOURNEY_IDLE_MS","DENIED_KEYS","Set","isUnsafeKey","key","has","toLowerCase","finitePositiveInt","n","fallback","Number","isFinite","Math","floor","finiteTimeoutMs","clampMaxSteps","value","min","finiteSlowRequestMs","undefined","resolveJourneyTimeoutMs","timeoutMs","idleDefaultMs","ms","explicit"],"mappings":"AAAA,mEAAmE,GAEnE,OAAO,MAAMA,oBAAoB,GAAG;AACpC,OAAO,MAAMC,gBAAgB,IAAI;AACjC,OAAO,MAAMC,eAAe,GAAG;AAC/B,OAAO,MAAMC,qBAAqB,GAAG;AACrC,OAAO,MAAMC,8BAA8B,GAAG;AAC9C,OAAO,MAAMC,oBAAoB,IAAI;AACrC,OAAO,MAAMC,0BAA0B,KAAK,KAAK,KAAM;AAEvD,MAAMC,cAAc,IAAIC,IAAI;IACxB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAED,4FAA4F,GAC5F,OAAO,SAASC,YAAYC,GAAW;IACnC,OAAOH,YAAYI,GAAG,CAACD,IAAIE,WAAW;AAC1C;AAEA;;;CAGC,GACD,OAAO,SAASC,kBAAkBC,CAAU,EAAEC,QAAgB;IAC1D,IAAI,OAAOD,MAAM,YAAY,CAACE,OAAOC,QAAQ,CAACH,MAAMA,KAAK,GAAG;QACxD,OAAOC;IACX;IACA,OAAOG,KAAKC,KAAK,CAACL;AACtB;AAEA;;CAEC,GACD,OAAO,SAASM,gBAAgBN,CAAU;IACtC,IAAI,OAAOA,MAAM,YAAY,CAACE,OAAOC,QAAQ,CAACH,MAAMA,IAAI,GAAG;QACvD,OAAO;IACX;IACA,OAAOI,KAAKC,KAAK,CAACL;AACtB;AAEA,8EAA8E,GAC9E,OAAO,SAASO,cAAcP,CAAU;IACpC,MAAMQ,QAAQT,kBAAkBC,GAAGd;IACnC,OAAOkB,KAAKK,GAAG,CAACD,OAAOrB;AAC3B;AAEA,qEAAqE,GACrE,OAAO,SAASuB,oBAAoBV,CAAU;IAC1C,IAAI,OAAOA,MAAM,YAAY,CAACE,OAAOC,QAAQ,CAACH,MAAMA,IAAI,GAAG;QACvD,OAAOW;IACX;IACA,OAAOP,KAAKC,KAAK,CAACL;AACtB;AAEA,mFAAmF,GACnF,OAAO,SAASY,wBACZC,SAA6B,EAC7BC,gBAAwBtB,uBAAuB;IAE/C,IAAIqB,cAAcF,WAAW;QACzB,OAAO;YAAEI,IAAIT,gBAAgBQ;YAAgBE,UAAU;QAAM;IACjE;IACA,OAAO;QAAED,IAAIT,gBAAgBO;QAAYG,UAAU;IAAK;AAC5D"}
@@ -0,0 +1,39 @@
1
+ /** Verdict for attributed HTTP (abort / 4xx / similar). */
2
+ export type JourneyRequestPolicy = 'continue' | 'bad' | 'exclude';
3
+ /** Normalized facts adapters pass into policy resolvers (not axios/jqXHR). */
4
+ export interface JourneyHttpPolicyContext {
5
+ requestKey: string;
6
+ /** Present when an HTTP response exists; omitted on abort / hard network failure. */
7
+ status?: number;
8
+ aborted: boolean;
9
+ url?: string;
10
+ method?: string;
11
+ journeyName?: string;
12
+ stepName?: string;
13
+ }
14
+ /**
15
+ * Per-stamp HTTP scorer from {@link StepHandle.stamp}. Must be synchronous.
16
+ * Return a policy to set the journey verdict; omit / void to keep default scoring.
17
+ * Do not consume a fetch body (clone first if you need to read it).
18
+ */
19
+ export type JourneyHttpScore = (ctx: JourneyHttpScoreContext) => JourneyRequestPolicy | void | undefined;
20
+ /** Context for {@link JourneyHttpScore} — policy facts plus the transport req/res. */
21
+ export interface JourneyHttpScoreContext extends JourneyHttpPolicyContext {
22
+ durationMs: number;
23
+ /** Transport request (axios config, fetch input/init, jQuery ajax settings). */
24
+ request?: unknown;
25
+ /** Transport response (axios response, fetch Response, jqXHR). */
26
+ response?: unknown;
27
+ /** Rejection reason when the transport failed. */
28
+ error?: unknown;
29
+ }
30
+ /** Options for {@link StepHandle.stamp}. */
31
+ export interface JourneyStampOptions {
32
+ score?: JourneyHttpScore;
33
+ /** Skip scoring for this stamped request. Ignore wins over `score`. */
34
+ ignore?: boolean;
35
+ }
36
+ export type RequestPolicyConfig = JourneyRequestPolicy | ((ctx: JourneyHttpPolicyContext) => JourneyRequestPolicy);
37
+ export declare function resolveRequestPolicy(config: RequestPolicyConfig | undefined, fallback: JourneyRequestPolicy, ctx: JourneyHttpPolicyContext): JourneyRequestPolicy;
38
+ export declare function isJourneyRequestPolicy(value: unknown): value is JourneyRequestPolicy;
39
+ //# sourceMappingURL=request-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-policy.d.ts","sourceRoot":"","sources":["../../src/core/request-policy.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,CAAC;AAElE,8EAA8E;AAC9E,MAAM,WAAW,wBAAwB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC3B,GAAG,EAAE,uBAAuB,KAC3B,oBAAoB,GAAG,IAAI,GAAG,SAAS,CAAC;AAE7C,sFAAsF;AACtF,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kDAAkD;IAClD,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAChC,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,uEAAuE;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,mBAAmB,GAC3B,oBAAoB,GAAG,CAAC,CAAC,GAAG,EAAE,wBAAwB,KAAK,oBAAoB,CAAC,CAAC;AAErF,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,mBAAmB,GAAG,SAAS,EACvC,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,EAAE,wBAAwB,GAC9B,oBAAoB,CAYtB;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAEpF"}
@@ -0,0 +1,18 @@
1
+ /** Verdict for attributed HTTP (abort / 4xx / similar). */ export function resolveRequestPolicy(config, fallback, ctx) {
2
+ if (config === undefined) {
3
+ return fallback;
4
+ }
5
+ if (typeof config === 'function') {
6
+ try {
7
+ return config(ctx);
8
+ } catch (unused) {
9
+ return fallback;
10
+ }
11
+ }
12
+ return config;
13
+ }
14
+ export function isJourneyRequestPolicy(value) {
15
+ return value === 'continue' || value === 'bad' || value === 'exclude';
16
+ }
17
+
18
+ //# sourceMappingURL=request-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/request-policy.ts"],"sourcesContent":["/** Verdict for attributed HTTP (abort / 4xx / similar). */\nexport type JourneyRequestPolicy = 'continue' | 'bad' | 'exclude';\n\n/** Normalized facts adapters pass into policy resolvers (not axios/jqXHR). */\nexport interface JourneyHttpPolicyContext {\n requestKey: string;\n /** Present when an HTTP response exists; omitted on abort / hard network failure. */\n status?: number;\n aborted: boolean;\n url?: string;\n method?: string;\n journeyName?: string;\n stepName?: string;\n}\n\n/**\n * Per-stamp HTTP scorer from {@link StepHandle.stamp}. Must be synchronous.\n * Return a policy to set the journey verdict; omit / void to keep default scoring.\n * Do not consume a fetch body (clone first if you need to read it).\n */\nexport type JourneyHttpScore = (\n ctx: JourneyHttpScoreContext\n) => JourneyRequestPolicy | void | undefined;\n\n/** Context for {@link JourneyHttpScore} — policy facts plus the transport req/res. */\nexport interface JourneyHttpScoreContext extends JourneyHttpPolicyContext {\n durationMs: number;\n /** Transport request (axios config, fetch input/init, jQuery ajax settings). */\n request?: unknown;\n /** Transport response (axios response, fetch Response, jqXHR). */\n response?: unknown;\n /** Rejection reason when the transport failed. */\n error?: unknown;\n}\n\n/** Options for {@link StepHandle.stamp}. */\nexport interface JourneyStampOptions {\n score?: JourneyHttpScore;\n /** Skip scoring for this stamped request. Ignore wins over `score`. */\n ignore?: boolean;\n}\n\nexport type RequestPolicyConfig =\n JourneyRequestPolicy | ((ctx: JourneyHttpPolicyContext) => JourneyRequestPolicy);\n\nexport function resolveRequestPolicy(\n config: RequestPolicyConfig | undefined,\n fallback: JourneyRequestPolicy,\n ctx: JourneyHttpPolicyContext\n): JourneyRequestPolicy {\n if (config === undefined) {\n return fallback;\n }\n if (typeof config === 'function') {\n try {\n return config(ctx);\n } catch {\n return fallback;\n }\n }\n return config;\n}\n\nexport function isJourneyRequestPolicy(value: unknown): value is JourneyRequestPolicy {\n return value === 'continue' || value === 'bad' || value === 'exclude';\n}\n"],"names":["resolveRequestPolicy","config","fallback","ctx","undefined","isJourneyRequestPolicy","value"],"mappings":"AAAA,yDAAyD,GA6CzD,OAAO,SAASA,qBACZC,MAAuC,EACvCC,QAA8B,EAC9BC,GAA6B;IAE7B,IAAIF,WAAWG,WAAW;QACtB,OAAOF;IACX;IACA,IAAI,OAAOD,WAAW,YAAY;QAC9B,IAAI;YACA,OAAOA,OAAOE;QAClB,EAAE,eAAM;YACJ,OAAOD;QACX;IACJ;IACA,OAAOD;AACX;AAEA,OAAO,SAASI,uBAAuBC,KAAc;IACjD,OAAOA,UAAU,cAAcA,UAAU,SAASA,UAAU;AAChE"}