@botonic/core 0.56.0-alpha.0 → 0.57.0-rslib-esm.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/lib/constants.js +8 -0
  2. package/lib/constants.js.map +1 -0
  3. package/lib/{esm/core-bot.d.ts → core-bot.d.ts} +3 -3
  4. package/lib/{cjs/core-bot.js → core-bot.js} +87 -50
  5. package/lib/core-bot.js.map +1 -0
  6. package/lib/debug/index.d.ts +1 -0
  7. package/lib/debug/index.js +6 -0
  8. package/lib/debug/index.js.map +1 -0
  9. package/lib/{cjs/debug → debug}/inspector.d.ts +1 -1
  10. package/lib/{cjs/debug → debug}/inspector.js +27 -21
  11. package/lib/debug/inspector.js.map +1 -0
  12. package/lib/{cjs/handoff.d.ts → handoff.d.ts} +1 -1
  13. package/lib/{esm/handoff.js → handoff.js} +82 -53
  14. package/lib/handoff.js.map +1 -0
  15. package/lib/{esm/hubtype-service.d.ts → hubtype-service.d.ts} +3 -3
  16. package/lib/{cjs/hubtype-service.js → hubtype-service.js} +100 -64
  17. package/lib/hubtype-service.js.map +1 -0
  18. package/lib/index.d.ts +9 -0
  19. package/lib/index.js +22 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/{esm/models → models}/ai-agents.d.ts +1 -8
  22. package/lib/models/ai-agents.js +30 -0
  23. package/lib/models/ai-agents.js.map +1 -0
  24. package/lib/models/bot-config.js +10 -0
  25. package/lib/models/bot-config.js.map +1 -0
  26. package/lib/{esm/models → models}/hubtype-analytics.d.ts +1 -1
  27. package/lib/{esm/models → models}/hubtype-analytics.js +10 -10
  28. package/lib/models/hubtype-analytics.js.map +1 -0
  29. package/lib/models/index.d.ts +4 -0
  30. package/lib/models/index.js +12 -0
  31. package/lib/models/index.js.map +1 -0
  32. package/lib/{esm/models → models}/legacy-types.js +24 -24
  33. package/lib/models/legacy-types.js.map +1 -0
  34. package/lib/{cjs/plugins.d.ts → plugins.d.ts} +1 -1
  35. package/lib/{esm/plugins.js → plugins.js} +7 -8
  36. package/lib/plugins.js.map +1 -0
  37. package/lib/pusher-utils.js +23 -0
  38. package/lib/pusher-utils.js.map +1 -0
  39. package/lib/routing/index.d.ts +2 -0
  40. package/lib/routing/index.js +8 -0
  41. package/lib/routing/index.js.map +1 -0
  42. package/lib/{cjs/routing → routing}/router-utils.d.ts +1 -1
  43. package/lib/{cjs/routing → routing}/router-utils.js +37 -30
  44. package/lib/routing/router-utils.js.map +1 -0
  45. package/lib/{cjs/routing → routing}/router.d.ts +2 -2
  46. package/lib/routing/router.js +333 -0
  47. package/lib/routing/router.js.map +1 -0
  48. package/lib/{esm/testing → testing}/index.d.ts +1 -1
  49. package/lib/testing/index.js +162 -0
  50. package/lib/testing/index.js.map +1 -0
  51. package/lib/{cjs/utils → utils}/bot-config.d.ts +1 -1
  52. package/lib/{esm/utils → utils}/bot-config.js +57 -28
  53. package/lib/utils/bot-config.js.map +1 -0
  54. package/lib/{cjs/utils → utils}/check-providers.d.ts +1 -1
  55. package/lib/utils/check-providers.js +31 -0
  56. package/lib/utils/check-providers.js.map +1 -0
  57. package/lib/utils/functional.js +69 -0
  58. package/lib/utils/functional.js.map +1 -0
  59. package/lib/utils/index.d.ts +3 -0
  60. package/lib/utils/index.js +10 -0
  61. package/lib/utils/index.js.map +1 -0
  62. package/package.json +14 -12
  63. package/src/hubtype-service.ts +4 -2
  64. package/src/models/ai-agents.ts +0 -9
  65. package/lib/cjs/constants.js +0 -8
  66. package/lib/cjs/constants.js.map +0 -1
  67. package/lib/cjs/core-bot.d.ts +0 -43
  68. package/lib/cjs/core-bot.js.map +0 -1
  69. package/lib/cjs/debug/index.d.ts +0 -1
  70. package/lib/cjs/debug/index.js +0 -5
  71. package/lib/cjs/debug/index.js.map +0 -1
  72. package/lib/cjs/debug/inspector.js.map +0 -1
  73. package/lib/cjs/handoff.js +0 -238
  74. package/lib/cjs/handoff.js.map +0 -1
  75. package/lib/cjs/hubtype-service.d.ts +0 -58
  76. package/lib/cjs/hubtype-service.js.map +0 -1
  77. package/lib/cjs/index.d.ts +0 -9
  78. package/lib/cjs/index.js +0 -13
  79. package/lib/cjs/index.js.map +0 -1
  80. package/lib/cjs/models/ai-agents.d.ts +0 -147
  81. package/lib/cjs/models/ai-agents.js +0 -31
  82. package/lib/cjs/models/ai-agents.js.map +0 -1
  83. package/lib/cjs/models/bot-config.js +0 -10
  84. package/lib/cjs/models/bot-config.js.map +0 -1
  85. package/lib/cjs/models/hubtype-analytics.d.ts +0 -210
  86. package/lib/cjs/models/hubtype-analytics.js +0 -38
  87. package/lib/cjs/models/hubtype-analytics.js.map +0 -1
  88. package/lib/cjs/models/index.d.ts +0 -4
  89. package/lib/cjs/models/index.js +0 -8
  90. package/lib/cjs/models/index.js.map +0 -1
  91. package/lib/cjs/models/legacy-types.js +0 -84
  92. package/lib/cjs/models/legacy-types.js.map +0 -1
  93. package/lib/cjs/plugins.js +0 -24
  94. package/lib/cjs/plugins.js.map +0 -1
  95. package/lib/cjs/pusher-utils.js +0 -18
  96. package/lib/cjs/pusher-utils.js.map +0 -1
  97. package/lib/cjs/routing/index.d.ts +0 -2
  98. package/lib/cjs/routing/index.js +0 -6
  99. package/lib/cjs/routing/index.js.map +0 -1
  100. package/lib/cjs/routing/router-utils.js.map +0 -1
  101. package/lib/cjs/routing/router.js +0 -330
  102. package/lib/cjs/routing/router.js.map +0 -1
  103. package/lib/cjs/testing/index.d.ts +0 -91
  104. package/lib/cjs/testing/index.js +0 -196
  105. package/lib/cjs/testing/index.js.map +0 -1
  106. package/lib/cjs/utils/bot-config.js +0 -94
  107. package/lib/cjs/utils/bot-config.js.map +0 -1
  108. package/lib/cjs/utils/check-providers.js +0 -34
  109. package/lib/cjs/utils/check-providers.js.map +0 -1
  110. package/lib/cjs/utils/functional.js +0 -88
  111. package/lib/cjs/utils/functional.js.map +0 -1
  112. package/lib/cjs/utils/index.d.ts +0 -3
  113. package/lib/cjs/utils/index.js +0 -7
  114. package/lib/cjs/utils/index.js.map +0 -1
  115. package/lib/esm/constants.d.ts +0 -4
  116. package/lib/esm/constants.js +0 -8
  117. package/lib/esm/constants.js.map +0 -1
  118. package/lib/esm/core-bot.js +0 -205
  119. package/lib/esm/core-bot.js.map +0 -1
  120. package/lib/esm/debug/index.d.ts +0 -1
  121. package/lib/esm/debug/index.js +0 -5
  122. package/lib/esm/debug/index.js.map +0 -1
  123. package/lib/esm/debug/inspector.d.ts +0 -24
  124. package/lib/esm/debug/inspector.js +0 -70
  125. package/lib/esm/debug/inspector.js.map +0 -1
  126. package/lib/esm/handoff.d.ts +0 -110
  127. package/lib/esm/handoff.js.map +0 -1
  128. package/lib/esm/hubtype-service.js +0 -205
  129. package/lib/esm/hubtype-service.js.map +0 -1
  130. package/lib/esm/index.d.ts +0 -9
  131. package/lib/esm/index.js +0 -13
  132. package/lib/esm/index.js.map +0 -1
  133. package/lib/esm/models/ai-agents.js +0 -31
  134. package/lib/esm/models/ai-agents.js.map +0 -1
  135. package/lib/esm/models/bot-config.d.ts +0 -24
  136. package/lib/esm/models/bot-config.js +0 -10
  137. package/lib/esm/models/bot-config.js.map +0 -1
  138. package/lib/esm/models/hubtype-analytics.js.map +0 -1
  139. package/lib/esm/models/index.d.ts +0 -4
  140. package/lib/esm/models/index.js +0 -8
  141. package/lib/esm/models/index.js.map +0 -1
  142. package/lib/esm/models/legacy-types.d.ts +0 -332
  143. package/lib/esm/models/legacy-types.js.map +0 -1
  144. package/lib/esm/plugins.d.ts +0 -9
  145. package/lib/esm/plugins.js.map +0 -1
  146. package/lib/esm/pusher-utils.d.ts +0 -7
  147. package/lib/esm/pusher-utils.js +0 -18
  148. package/lib/esm/pusher-utils.js.map +0 -1
  149. package/lib/esm/routing/index.d.ts +0 -2
  150. package/lib/esm/routing/index.js +0 -6
  151. package/lib/esm/routing/index.js.map +0 -1
  152. package/lib/esm/routing/router-utils.d.ts +0 -11
  153. package/lib/esm/routing/router-utils.js +0 -96
  154. package/lib/esm/routing/router-utils.js.map +0 -1
  155. package/lib/esm/routing/router.d.ts +0 -54
  156. package/lib/esm/routing/router.js +0 -330
  157. package/lib/esm/routing/router.js.map +0 -1
  158. package/lib/esm/testing/index.js +0 -196
  159. package/lib/esm/testing/index.js.map +0 -1
  160. package/lib/esm/utils/bot-config.d.ts +0 -4
  161. package/lib/esm/utils/bot-config.js.map +0 -1
  162. package/lib/esm/utils/check-providers.d.ts +0 -8
  163. package/lib/esm/utils/check-providers.js +0 -34
  164. package/lib/esm/utils/check-providers.js.map +0 -1
  165. package/lib/esm/utils/functional.d.ts +0 -10
  166. package/lib/esm/utils/functional.js +0 -88
  167. package/lib/esm/utils/functional.js.map +0 -1
  168. package/lib/esm/utils/index.d.ts +0 -3
  169. package/lib/esm/utils/index.js +0 -7
  170. package/lib/esm/utils/index.js.map +0 -1
  171. /package/lib/{cjs/constants.d.ts → constants.d.ts} +0 -0
  172. /package/lib/{cjs/models → models}/bot-config.d.ts +0 -0
  173. /package/lib/{cjs/models → models}/legacy-types.d.ts +0 -0
  174. /package/lib/{cjs/pusher-utils.d.ts → pusher-utils.d.ts} +0 -0
  175. /package/lib/{cjs/utils → utils}/functional.d.ts +0 -0
@@ -0,0 +1,333 @@
1
+ import { NOT_FOUND_PATH } from "../constants.js";
2
+ import { RouteInspector } from "../debug/inspector.js";
3
+ import { cloneObject } from "../utils/index.js";
4
+ import { getEmptyAction, getNotFoundAction, getPathParamsFromPathPayload, isPathPayload } from "./router-utils.js";
5
+
6
+
7
+
8
+
9
+
10
+ function _define_property(obj, key, value) {
11
+ if (key in obj) {
12
+ Object.defineProperty(obj, key, {
13
+ value: value,
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true
17
+ });
18
+ } else obj[key] = value;
19
+ return obj;
20
+ }
21
+
22
+
23
+
24
+
25
+ class Router {
26
+ /**
27
+ * Processes an input and return a representation of the new bot state.
28
+ * The algorithm is splitted in two main parts:
29
+ * 1. Getting the current routing state.
30
+ * 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
31
+ * The new bot state can return three type of actions:
32
+ * - action: an action directly resolved from a matching route
33
+ * - emptyAction: optional action that can exists or not only within childRoutes
34
+ * - fallbackAction: any other action that acts as a fallback (404, )
35
+ */ // eslint-disable-next-line complexity
36
+ processInput(input, session, lastRoutePath = null) {
37
+ session.__retries = session?.__retries ?? 0;
38
+ // 1. Getting the current routing state.
39
+ const { currentRoute, matchedRoute, params, isFlowBroken } = this.getRoutingState(input, session, lastRoutePath);
40
+ const currentRoutePath = currentRoute?.path ?? null;
41
+ const matchedRoutePath = matchedRoute?.path ?? null;
42
+ // 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
43
+ /**
44
+ * Redirect Scenario:
45
+ * We have matched a redirect route with a given redirection path, so we try to obtain the redirectionRoute with getRouteByPath.
46
+ * Independently of whether the redirectionRoute is found or not, the intent is to trigger a redirection which by definition breaks the flow, so retries are set to 0.
47
+ * It has preference over ignoring retries.
48
+ */ if (matchedRoute?.redirect) {
49
+ session.__retries = 0;
50
+ const redirectionRoute = this.getRouteByPath(matchedRoute.redirect);
51
+ if (redirectionRoute) {
52
+ return {
53
+ action: redirectionRoute.action,
54
+ emptyAction: getEmptyAction(redirectionRoute.childRoutes),
55
+ fallbackAction: null,
56
+ lastRoutePath: matchedRoute.redirect,
57
+ params
58
+ };
59
+ }
60
+ return {
61
+ action: null,
62
+ emptyAction: null,
63
+ fallbackAction: getNotFoundAction(input, this.routes),
64
+ lastRoutePath: null,
65
+ params
66
+ };
67
+ }
68
+ /**
69
+ * Ignore Retry Scenario:
70
+ * We have matched a route with an ignore retry, so we return directly the new bot state. The intent is to break the flow, so retries are set to 0.
71
+ */ if (matchedRoute?.ignoreRetry) {
72
+ session.__retries = 0;
73
+ return {
74
+ action: matchedRoute.action,
75
+ emptyAction: getEmptyAction(matchedRoute.childRoutes),
76
+ fallbackAction: null,
77
+ lastRoutePath: matchedRoutePath,
78
+ params
79
+ };
80
+ }
81
+ /**
82
+ * Retry Scenario:
83
+ * We were in a route which had retries enabled, so we check if the number of retries is exceeded.
84
+ * If we have not surpassed the limit of retries and we haven't matched an ignoreRetry route, update them, and then return the new bot state.
85
+ */ if (isFlowBroken && currentRoute && currentRoute.retry && session.__retries < currentRoute.retry) {
86
+ session.__retries = session.__retries !== 0 ? session.__retries + 1 : 1;
87
+ if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {
88
+ return {
89
+ action: currentRoute.action,
90
+ emptyAction: getEmptyAction(matchedRoute.childRoutes),
91
+ fallbackAction: matchedRoute.action,
92
+ lastRoutePath: currentRoutePath,
93
+ params
94
+ };
95
+ }
96
+ return {
97
+ action: currentRoute.action ?? null,
98
+ emptyAction: getEmptyAction(currentRoute.childRoutes),
99
+ fallbackAction: getNotFoundAction(input, this.routes),
100
+ lastRoutePath: currentRoutePath,
101
+ params
102
+ };
103
+ }
104
+ /**
105
+ * Default Scenario:
106
+ * We have matched a route or not, but we don't need to execute retries logic, so retries stay to 0.
107
+ */ session.__retries = 0;
108
+ /**
109
+ * Matching Route Scenario:
110
+ * We have matched a route, so we return the new bot state.
111
+ */ if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {
112
+ return {
113
+ action: matchedRoute.action ?? null,
114
+ emptyAction: getEmptyAction(matchedRoute.childRoutes),
115
+ fallbackAction: null,
116
+ lastRoutePath: matchedRoutePath,
117
+ params
118
+ };
119
+ }
120
+ /**
121
+ * 404 Scenario (No Route Found):
122
+ * We have not matched any route, so we return the new bot state.
123
+ */ return {
124
+ action: null,
125
+ emptyAction: null,
126
+ fallbackAction: getNotFoundAction(input, this.routes),
127
+ params,
128
+ lastRoutePath: currentRoutePath
129
+ };
130
+ }
131
+ /**
132
+ * Find the route that matches the given input, if it match with some of the entries, return the whole Route of the entry with optional params captured if matcher was a regex.
133
+ * IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
134
+ * */ getRoute(input, routes, session, lastRoutePath) {
135
+ let params = {};
136
+ const route = routes.find((r)=>Object.entries(r).filter(([key, _])=>key !== 'action' && key !== 'childRoutes' && key !== 'path').some(([key, value])=>{
137
+ const match = this.matchRoute(r, key, value, input, session, lastRoutePath);
138
+ try {
139
+ if (match !== null && typeof match !== 'boolean' && match.groups) {
140
+ // Strip '[Object: null prototype]' from groups result: https://stackoverflow.com/a/62945609/6237608
141
+ params = {
142
+ ...match.groups
143
+ };
144
+ }
145
+ } catch (_e) {}
146
+ return Boolean(match);
147
+ }));
148
+ if (route) {
149
+ return {
150
+ route: cloneObject(route),
151
+ params
152
+ };
153
+ }
154
+ return null;
155
+ }
156
+ /**
157
+ * Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.
158
+ * IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
159
+ * */ getRouteByPath(path, routeList = this.routes) {
160
+ if (!path) {
161
+ return null;
162
+ }
163
+ const [currentPath, ...childPath] = path.split('/');
164
+ for (const route of routeList){
165
+ // iterate over all routeList
166
+ if (route.path === currentPath) {
167
+ if (route.childRoutes?.length && childPath.length > 0) {
168
+ // evaluate childroute over next actions
169
+ const computedRoute = this.getRouteByPath(childPath.join('/'), route.childRoutes);
170
+ // IMPORTANT: Returning a new object to avoid modifying dev routes and introduce side effects
171
+ if (computedRoute) {
172
+ return cloneObject(computedRoute);
173
+ }
174
+ } else if (childPath.length === 0) {
175
+ return cloneObject(route) // last action and found route
176
+ ;
177
+ }
178
+ }
179
+ }
180
+ return null;
181
+ }
182
+ /**
183
+ * Returns the matched value for a specific route.
184
+ * Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
185
+ * Matchers: (string: exact match | regex: regular expression match | function: return true)
186
+ * input: user input object, e.g.: {type: 'text', data: 'Hi'}
187
+ * */ matchRoute(route, prop, matcher, input, session, lastRoutePath) {
188
+ let value = null;
189
+ if (Object.keys(input).indexOf(prop) > -1) {
190
+ value = input[prop];
191
+ } else if (prop === 'text') {
192
+ value = input.data;
193
+ } else if (prop === 'input') {
194
+ value = input;
195
+ } else if (prop === 'session') {
196
+ value = session;
197
+ } else if (prop === 'request') {
198
+ value = {
199
+ input,
200
+ session,
201
+ lastRoutePath
202
+ };
203
+ }
204
+ const matched = this.matchValue(matcher, value);
205
+ if (matched) {
206
+ this.routeInspector.routeMatched(route, prop, matcher, value);
207
+ } else {
208
+ this.routeInspector.routeNotMatched(route, prop, matcher, value);
209
+ }
210
+ return matched;
211
+ }
212
+ /**
213
+ * Runs the matcher against the given value.
214
+ * If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.
215
+ * */ matchValue(matcher, value) {
216
+ if (typeof matcher === 'string') {
217
+ return value === matcher;
218
+ }
219
+ if (matcher instanceof RegExp) {
220
+ if (value === undefined || value === null) {
221
+ return false;
222
+ }
223
+ return matcher.exec(value);
224
+ }
225
+ if (typeof matcher === 'function') {
226
+ return matcher(value);
227
+ }
228
+ return false;
229
+ }
230
+ /**
231
+ * It resolves the current state of navigation. Two scenarios:
232
+ * 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).
233
+ * 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).
234
+ * */ getRoutingState(input, session, lastRoutePath) {
235
+ const currentRoute = this.getRouteByPath(lastRoutePath);
236
+ if (currentRoute && lastRoutePath) {
237
+ currentRoute.path = lastRoutePath;
238
+ }
239
+ if (typeof input.payload === 'string' && isPathPayload(input.payload)) {
240
+ return this.getRoutingStateFromPathPayload(currentRoute, input.payload);
241
+ }
242
+ return this.getRoutingStateFromInput(currentRoute, input, session);
243
+ }
244
+ /**
245
+ * Given a non path payload input, try to run it against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
246
+ * */ getRoutingStateFromInput(currentRoute, input, session) {
247
+ // get route depending of current ChildRoutes
248
+ if (currentRoute?.childRoutes) {
249
+ const routeParams = this.getRoute(input, currentRoute.childRoutes, session, currentRoute.path);
250
+ if (routeParams) {
251
+ return {
252
+ currentRoute,
253
+ matchedRoute: {
254
+ ...routeParams.route,
255
+ path: routeParams.route && currentRoute.path ? `${currentRoute.path}/${routeParams.route.path}` : currentRoute.path
256
+ },
257
+ params: routeParams.params,
258
+ isFlowBroken: false
259
+ };
260
+ }
261
+ }
262
+ /**
263
+ * we couldn't find a route in the state of the currentRoute childRoutes,
264
+ * so let's find in the general routes
265
+ */ const routeParams = this.getRoute(input, this.routes, session, currentRoute?.path ?? null);
266
+ const isFlowBroken = Boolean(currentRoute?.path);
267
+ if (routeParams?.route) {
268
+ return {
269
+ currentRoute,
270
+ matchedRoute: {
271
+ ...routeParams.route,
272
+ path: routeParams.route?.path ?? null
273
+ },
274
+ params: routeParams.params,
275
+ isFlowBroken
276
+ };
277
+ }
278
+ return {
279
+ currentRoute,
280
+ matchedRoute: null,
281
+ params: {},
282
+ isFlowBroken
283
+ };
284
+ }
285
+ /**
286
+ * Given a path payload input, try to run the path against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
287
+ * */ getRoutingStateFromPathPayload(currentRoute, pathPayload) {
288
+ const { path, params } = getPathParamsFromPathPayload(pathPayload);
289
+ /**
290
+ * shorthand function to update the matching information given a path
291
+ */ const getRoutingStateFromPath = (seekPath)=>{
292
+ const matchedRoute = this.getRouteByPath(seekPath);
293
+ if (!matchedRoute) {
294
+ return {
295
+ currentRoute,
296
+ matchedRoute: null,
297
+ params: {},
298
+ isFlowBroken: true
299
+ };
300
+ }
301
+ return {
302
+ currentRoute,
303
+ matchedRoute: {
304
+ ...matchedRoute,
305
+ path: seekPath
306
+ },
307
+ params,
308
+ isFlowBroken: false
309
+ };
310
+ };
311
+ /**
312
+ * Given a valid path: 'Flow1/Subflow1' we are in one of the two scenarios below.
313
+ */ // 1. Received __PATH_PAYLOAD__Subflow2, so we need to first try to concatenate it with Flow1 (lastRoutePath)
314
+ if (currentRoute?.path) {
315
+ const routingState = getRoutingStateFromPath(`${currentRoute.path}/${path}`);
316
+ if (routingState.matchedRoute) {
317
+ return routingState;
318
+ }
319
+ }
320
+ // 2. Received __PATH_PAYLOAD__Flow1/Subflow1, so we can resolve it directly
321
+ return getRoutingStateFromPath(path);
322
+ }
323
+ constructor(routes, routeInspector = undefined){
324
+ _define_property(this, "routes", void 0);
325
+ _define_property(this, "routeInspector", void 0);
326
+ this.routes = routes;
327
+ this.routeInspector = routeInspector || new RouteInspector();
328
+ }
329
+ }
330
+
331
+ export { Router };
332
+
333
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing/router.js","sources":["../../src/routing/router.ts"],"sourcesContent":["import { NOT_FOUND_PATH } from '../constants'\nimport { RouteInspector } from '../debug/inspector'\nimport type {\n Input,\n MatchedValue,\n Matcher,\n MatchingProp,\n Nullable,\n ProcessInputResult,\n Route,\n RouteParams,\n RoutePath,\n RoutingState,\n Session,\n} from '../models'\nimport { cloneObject } from '../utils'\nimport {\n getEmptyAction,\n getNotFoundAction,\n getPathParamsFromPathPayload,\n isPathPayload,\n} from './router-utils'\n\nexport class Router {\n routes: Route[]\n routeInspector: RouteInspector\n\n constructor(\n routes: Route[],\n routeInspector: RouteInspector | undefined = undefined\n ) {\n this.routes = routes\n this.routeInspector = routeInspector || new RouteInspector()\n }\n\n /**\n * Processes an input and return a representation of the new bot state.\n * The algorithm is splitted in two main parts:\n * 1. Getting the current routing state.\n * 2. Given a routing state, resolve the different possible scenarios and return the new bot state.\n * The new bot state can return three type of actions:\n * - action: an action directly resolved from a matching route\n * - emptyAction: optional action that can exists or not only within childRoutes\n * - fallbackAction: any other action that acts as a fallback (404, )\n */\n\n // eslint-disable-next-line complexity\n processInput(\n input: Input,\n session: Session,\n lastRoutePath: RoutePath = null\n ): ProcessInputResult {\n session.__retries = session?.__retries ?? 0\n\n // 1. Getting the current routing state.\n const { currentRoute, matchedRoute, params, isFlowBroken } =\n this.getRoutingState(input, session, lastRoutePath)\n\n const currentRoutePath = currentRoute?.path ?? null\n const matchedRoutePath = matchedRoute?.path ?? null\n\n // 2. Given a routing state, resolve the different possible scenarios and return the new bot state.\n\n /**\n * Redirect Scenario:\n * We have matched a redirect route with a given redirection path, so we try to obtain the redirectionRoute with getRouteByPath.\n * Independently of whether the redirectionRoute is found or not, the intent is to trigger a redirection which by definition breaks the flow, so retries are set to 0.\n * It has preference over ignoring retries.\n */\n if (matchedRoute?.redirect) {\n session.__retries = 0\n const redirectionRoute = this.getRouteByPath(matchedRoute.redirect)\n if (redirectionRoute) {\n return {\n action: redirectionRoute.action,\n emptyAction: getEmptyAction(redirectionRoute.childRoutes),\n fallbackAction: null,\n lastRoutePath: matchedRoute.redirect,\n params,\n }\n }\n return {\n action: null,\n emptyAction: null,\n fallbackAction: getNotFoundAction(input, this.routes),\n lastRoutePath: null,\n params,\n }\n }\n\n /**\n * Ignore Retry Scenario:\n * We have matched a route with an ignore retry, so we return directly the new bot state. The intent is to break the flow, so retries are set to 0.\n */\n if (matchedRoute?.ignoreRetry) {\n session.__retries = 0\n return {\n action: matchedRoute.action,\n emptyAction: getEmptyAction(matchedRoute.childRoutes),\n fallbackAction: null,\n lastRoutePath: matchedRoutePath,\n params,\n }\n }\n\n /**\n * Retry Scenario:\n * We were in a route which had retries enabled, so we check if the number of retries is exceeded.\n * If we have not surpassed the limit of retries and we haven't matched an ignoreRetry route, update them, and then return the new bot state.\n */\n if (\n isFlowBroken &&\n currentRoute &&\n currentRoute.retry &&\n session.__retries < currentRoute.retry\n ) {\n session.__retries = session.__retries !== 0 ? session.__retries + 1 : 1\n if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {\n return {\n action: currentRoute.action,\n emptyAction: getEmptyAction(matchedRoute.childRoutes),\n fallbackAction: matchedRoute.action,\n lastRoutePath: currentRoutePath,\n params,\n }\n }\n return {\n action: currentRoute.action ?? null,\n emptyAction: getEmptyAction(currentRoute.childRoutes),\n fallbackAction: getNotFoundAction(input, this.routes),\n lastRoutePath: currentRoutePath,\n params,\n }\n }\n\n /**\n * Default Scenario:\n * We have matched a route or not, but we don't need to execute retries logic, so retries stay to 0.\n */\n session.__retries = 0\n\n /**\n * Matching Route Scenario:\n * We have matched a route, so we return the new bot state.\n */\n if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {\n return {\n action: matchedRoute.action ?? null,\n emptyAction: getEmptyAction(matchedRoute.childRoutes),\n fallbackAction: null,\n lastRoutePath: matchedRoutePath,\n params,\n }\n }\n\n /**\n * 404 Scenario (No Route Found):\n * We have not matched any route, so we return the new bot state.\n */\n return {\n action: null,\n emptyAction: null,\n fallbackAction: getNotFoundAction(input, this.routes),\n params,\n lastRoutePath: currentRoutePath,\n }\n }\n\n /**\n * Find the route that matches the given input, if it match with some of the entries, return the whole Route of the entry with optional params captured if matcher was a regex.\n * IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects\n * */\n getRoute(\n input: Input | Partial<Input>,\n routes: Route[],\n session: Session,\n lastRoutePath: RoutePath\n ): RouteParams | null {\n let params = {}\n const route = routes.find(r =>\n Object.entries(r)\n .filter(\n ([key, _]) =>\n key !== 'action' && key !== 'childRoutes' && key !== 'path'\n )\n .some(([key, value]) => {\n const match = this.matchRoute(\n r,\n key as MatchingProp,\n value as Matcher,\n input as Input,\n session,\n lastRoutePath\n )\n try {\n if (match !== null && typeof match !== 'boolean' && match.groups) {\n // Strip '[Object: null prototype]' from groups result: https://stackoverflow.com/a/62945609/6237608\n params = { ...match.groups }\n }\n } catch (_e) {}\n return Boolean(match)\n })\n )\n if (route) {\n return { route: cloneObject(route), params }\n }\n return null\n }\n\n /**\n * Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.\n * IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects\n * */\n getRouteByPath(\n path: RoutePath,\n routeList: Route[] = this.routes\n ): Nullable<Route> {\n if (!path) {\n return null\n }\n const [currentPath, ...childPath] = path.split('/')\n for (const route of routeList) {\n // iterate over all routeList\n if (route.path === currentPath) {\n if (route.childRoutes?.length && childPath.length > 0) {\n // evaluate childroute over next actions\n const computedRoute = this.getRouteByPath(\n childPath.join('/'),\n route.childRoutes\n )\n // IMPORTANT: Returning a new object to avoid modifying dev routes and introduce side effects\n if (computedRoute) {\n return cloneObject(computedRoute)\n }\n } else if (childPath.length === 0) {\n return cloneObject(route) // last action and found route\n }\n }\n }\n return null\n }\n\n /**\n * Returns the matched value for a specific route.\n * Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)\n * Matchers: (string: exact match | regex: regular expression match | function: return true)\n * input: user input object, e.g.: {type: 'text', data: 'Hi'}\n * */\n matchRoute(\n route: Route,\n prop: MatchingProp,\n matcher: Matcher,\n input: Input,\n session: Session,\n lastRoutePath: RoutePath\n ): MatchedValue {\n let value: any = null\n if (Object.keys(input).indexOf(prop) > -1) {\n value = input[prop]\n } else if (prop === 'text') {\n value = input.data\n } else if (prop === 'input') {\n value = input\n } else if (prop === 'session') {\n value = session\n } else if (prop === 'request') {\n value = { input, session, lastRoutePath }\n }\n const matched = this.matchValue(matcher, value)\n if (matched) {\n this.routeInspector.routeMatched(route, prop, matcher, value)\n } else {\n this.routeInspector.routeNotMatched(route, prop, matcher, value)\n }\n return matched\n }\n\n /**\n * Runs the matcher against the given value.\n * If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.\n * */\n matchValue(matcher: Matcher, value: any): MatchedValue {\n if (typeof matcher === 'string') {\n return value === matcher\n }\n if (matcher instanceof RegExp) {\n if (value === undefined || value === null) {\n return false\n }\n return matcher.exec(value)\n }\n if (typeof matcher === 'function') {\n return matcher(value)\n }\n return false\n }\n\n /**\n * It resolves the current state of navigation. Two scenarios:\n * 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).\n * 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).\n * */\n getRoutingState(\n input: Input,\n session: Session,\n lastRoutePath: RoutePath\n ): RoutingState {\n const currentRoute = this.getRouteByPath(lastRoutePath)\n if (currentRoute && lastRoutePath) {\n currentRoute.path = lastRoutePath\n }\n if (typeof input.payload === 'string' && isPathPayload(input.payload)) {\n return this.getRoutingStateFromPathPayload(currentRoute, input.payload)\n }\n return this.getRoutingStateFromInput(currentRoute, input, session)\n }\n\n /**\n * Given a non path payload input, try to run it against the routes, update matching routes information in consequence and dictamine if the flow has been broken.\n * */\n getRoutingStateFromInput(\n currentRoute: Nullable<Route>,\n input: Input,\n session: Session\n ): RoutingState {\n // get route depending of current ChildRoutes\n if (currentRoute?.childRoutes) {\n const routeParams = this.getRoute(\n input,\n currentRoute.childRoutes,\n session,\n currentRoute.path\n )\n if (routeParams) {\n return {\n currentRoute,\n matchedRoute: {\n ...routeParams.route,\n path:\n routeParams.route && currentRoute.path\n ? `${currentRoute.path}/${routeParams.route.path}`\n : currentRoute.path,\n },\n params: routeParams.params,\n isFlowBroken: false,\n }\n }\n }\n /**\n * we couldn't find a route in the state of the currentRoute childRoutes,\n * so let's find in the general routes\n */\n const routeParams = this.getRoute(\n input,\n this.routes,\n session,\n currentRoute?.path ?? null\n )\n const isFlowBroken = Boolean(currentRoute?.path)\n if (routeParams?.route) {\n return {\n currentRoute,\n matchedRoute: {\n ...routeParams.route,\n path: routeParams.route?.path ?? null,\n },\n params: routeParams.params,\n isFlowBroken,\n }\n }\n return {\n currentRoute,\n matchedRoute: null,\n params: {},\n isFlowBroken,\n }\n }\n\n /**\n * Given a path payload input, try to run the path against the routes, update matching routes information in consequence and dictamine if the flow has been broken.\n * */\n getRoutingStateFromPathPayload(\n currentRoute: Nullable<Route>,\n pathPayload: string\n ): RoutingState {\n const { path, params } = getPathParamsFromPathPayload(pathPayload)\n /**\n * shorthand function to update the matching information given a path\n */\n const getRoutingStateFromPath = (seekPath: string): RoutingState => {\n const matchedRoute = this.getRouteByPath(seekPath)\n if (!matchedRoute) {\n return {\n currentRoute,\n matchedRoute: null,\n params: {},\n isFlowBroken: true,\n }\n }\n return {\n currentRoute,\n matchedRoute: { ...matchedRoute, path: seekPath },\n params,\n isFlowBroken: false,\n }\n }\n /**\n * Given a valid path: 'Flow1/Subflow1' we are in one of the two scenarios below.\n */\n // 1. Received __PATH_PAYLOAD__Subflow2, so we need to first try to concatenate it with Flow1 (lastRoutePath)\n if (currentRoute?.path) {\n const routingState = getRoutingStateFromPath(\n `${currentRoute.path}/${path}`\n )\n if (routingState.matchedRoute) {\n return routingState\n }\n }\n // 2. Received __PATH_PAYLOAD__Flow1/Subflow1, so we can resolve it directly\n return getRoutingStateFromPath(path as string)\n }\n}\n"],"names":["NOT_FOUND_PATH","RouteInspector","cloneObject","getEmptyAction","getNotFoundAction","getPathParamsFromPathPayload","isPathPayload","Router","input","session","lastRoutePath","currentRoute","matchedRoute","params","isFlowBroken","currentRoutePath","matchedRoutePath","redirectionRoute","routes","route","r","Object","key","_","value","match","_e","Boolean","path","routeList","currentPath","childPath","computedRoute","prop","matcher","matched","RegExp","undefined","routeParams","pathPayload","getRoutingStateFromPath","seekPath","routingState","routeInspector"],"mappings":";;;;;;;;;;;;;;;;;;;;AAA6C;AACM;AAcb;AAMf;AAEhB,MAAMO,MAAMA;IAYjB;;;;;;;;;GASC,GAED,sCAAsC;IACtC,aACEC,KAAY,EACZC,OAAgB,EAChBC,gBAA2B,IAAI,EACX;QACpBD,QAAQ,SAAS,GAAGA,SAAS,aAAa;QAE1C,wCAAwC;QACxC,MAAM,EAAEE,YAAY,EAAEC,YAAY,EAAEC,MAAM,EAAEC,YAAY,EAAE,GACxD,IAAI,CAAC,eAAe,CAACN,OAAOC,SAASC;QAEvC,MAAMK,mBAAmBJ,cAAc,QAAQ;QAC/C,MAAMK,mBAAmBJ,cAAc,QAAQ;QAE/C,mGAAmG;QAEnG;;;;;KAKC,GACD,IAAIA,cAAc,UAAU;YAC1BH,QAAQ,SAAS,GAAG;YACpB,MAAMQ,mBAAmB,IAAI,CAAC,cAAc,CAACL,aAAa,QAAQ;YAClE,IAAIK,kBAAkB;gBACpB,OAAO;oBACL,QAAQA,iBAAiB,MAAM;oBAC/B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EACL;QACd,MAAM,EAAEX,IAAI,EAAEf,MAAM,EAAE,GAAGR,4BAA4BA,CAACkC;QACtD;;KAEC,GACD,MAAMC,0BAA0B,CAACC;YAC/B,MAAM7B,eAAe,IAAI,CAAC,cAAc,CAAC6B;YACzC,IAAI,CAAC7B,cAAc;gBACjB,OAAO;oBACLD;oBACA,cAAc;oBACd,QAAQ,CAAC;oBACT,cAAc;gBAChB;YACF;YACA,OAAO;gBACLA;gBACA,cAAc;oBAAE,GAAGC,YAAY;oBAAE,MAAM6B;gBAAS;gBAChD5B;gBACA,cAAc;YAChB;QACF;QACA;;KAEC,GACD,8GAA8G;QAC9G,IAAIF,cAAc,MAAM;YACtB,MAAM+B,eAAeF,wBACnB,GAAG7B,aAAa,IAAI,CAAC,CAAC,EAAEiB,MAAM;YAEhC,IAAIc,aAAa,YAAY,EAAE;gBAC7B,OAAOA;YACT;QACF;QACA,4EAA4E;QAC5E,OAAOF,wBAAwBZ;IACjC;IAzYA,YACEV,MAAe,EACfyB,iBAA6CN,SAAS,CACtD;QANF;QACA;QAME,IAAI,CAAC,MAAM,GAAGnB;QACd,IAAI,CAAC,cAAc,GAAGyB,kBAAkB,IAAI1C,cAAcA;IAC5D;AAoYF"}
@@ -1,4 +1,4 @@
1
- import { type BotContext, type BotRequest, type BotSecrets, type BotSettings, type ContactInfo, type Input, type ProviderType, type ResolvedPlugins, type Session, type SessionUser } from '../models';
1
+ import { type BotContext, type BotRequest, type BotSecrets, type BotSettings, type ContactInfo, type Input, type ProviderType, type ResolvedPlugins, type Session, type SessionUser } from '../models/index.js';
2
2
  export declare const TEST_DEFAULTS: {
3
3
  HUBTYPE_API_URL: string;
4
4
  STATIC_URL: string;
@@ -0,0 +1,162 @@
1
+ import { INPUT, PROVIDER } from "../models/index.js";
2
+
3
+
4
+
5
+ // ---------------------------------------------------------------------------
6
+ // Default values
7
+ // ---------------------------------------------------------------------------
8
+ const TEST_DEFAULTS = {
9
+ HUBTYPE_API_URL: 'https://api.hubtype.com',
10
+ STATIC_URL: 'https://static.hubtype.com',
11
+ LITELLM_API_URL: 'https://api.litellm.com',
12
+ AZURE_OPENAI_API_BASE: 'https://api.openai.com',
13
+ AZURE_OPENAI_API_VERSION: '2026-02-01',
14
+ LANGUAGE_DETECTION_ENABLED: true,
15
+ HUBTYPE_ACCESS_TOKEN: 'testAccessToken',
16
+ LITELLM_API_KEY: 'testLiteLLMAPIKey',
17
+ AZURE_OPENAI_API_KEY: 'testAzureOpenAIAPIKey',
18
+ ACCESS_TOKEN: 'fake_access_token',
19
+ HUBTYPE_API_HOST: 'https://api.hubtype.com',
20
+ FLOW_THREAD_ID: 'testFlowThreadId',
21
+ BOT_ID: 'testBotId',
22
+ USER_ID: 'testUserId',
23
+ ORG_ID: 'testOrgId',
24
+ ORG_NAME: 'testOrg',
25
+ PROVIDER: PROVIDER.WEBCHAT,
26
+ LOCALE: 'en',
27
+ COUNTRY: 'US',
28
+ BOT_INTERACTION_ID: 'testInteractionId',
29
+ MESSAGE_ID: 'testMessageId',
30
+ LAST_ROUTE_PATH: ''
31
+ };
32
+ // ---------------------------------------------------------------------------
33
+ // Leaf factories
34
+ // ---------------------------------------------------------------------------
35
+ function createTestSettings(overrides) {
36
+ return {
37
+ HUBTYPE_API_URL: TEST_DEFAULTS.HUBTYPE_API_URL,
38
+ STATIC_URL: TEST_DEFAULTS.STATIC_URL,
39
+ LITELLM_API_URL: TEST_DEFAULTS.LITELLM_API_URL,
40
+ AZURE_OPENAI_API_BASE: TEST_DEFAULTS.AZURE_OPENAI_API_BASE,
41
+ AZURE_OPENAI_API_VERSION: TEST_DEFAULTS.AZURE_OPENAI_API_VERSION,
42
+ LANGUAGE_DETECTION_ENABLED: TEST_DEFAULTS.LANGUAGE_DETECTION_ENABLED,
43
+ CUSTOM_SHORT_URL_HOST: null,
44
+ custom: {},
45
+ ...overrides
46
+ };
47
+ }
48
+ function createTestSecrets(overrides) {
49
+ return {
50
+ HUBTYPE_ACCESS_TOKEN: TEST_DEFAULTS.HUBTYPE_ACCESS_TOKEN,
51
+ LITELLM_API_KEY: TEST_DEFAULTS.LITELLM_API_KEY,
52
+ AZURE_OPENAI_API_KEY: TEST_DEFAULTS.AZURE_OPENAI_API_KEY,
53
+ custom: {},
54
+ ...overrides
55
+ };
56
+ }
57
+ function createTestSessionUser(options) {
58
+ const locale = options?.locale ?? TEST_DEFAULTS.LOCALE;
59
+ const country = options?.country ?? TEST_DEFAULTS.COUNTRY;
60
+ return {
61
+ id: options?.id ?? TEST_DEFAULTS.USER_ID,
62
+ provider: options?.provider ?? TEST_DEFAULTS.PROVIDER,
63
+ locale,
64
+ country,
65
+ system_locale: options?.systemLocale ?? locale,
66
+ contact_info: options?.contactInfo ?? [],
67
+ extra_data: options?.extraData ?? {}
68
+ };
69
+ }
70
+ function createTestSession(options) {
71
+ return {
72
+ bot: {
73
+ id: options?.botId ?? TEST_DEFAULTS.BOT_ID
74
+ },
75
+ user: createTestSessionUser(options?.user),
76
+ organization: options?.organization ?? TEST_DEFAULTS.ORG_NAME,
77
+ organization_id: options?.organizationId ?? TEST_DEFAULTS.ORG_ID,
78
+ is_first_interaction: options?.isFirstInteraction ?? false,
79
+ is_test_integration: options?.isTestIntegration ?? false,
80
+ _access_token: options?.accessToken ?? TEST_DEFAULTS.ACCESS_TOKEN,
81
+ _hubtype_api: options?.hubtypeApi ?? TEST_DEFAULTS.HUBTYPE_API_HOST,
82
+ flow_thread_id: options?.flowThreadId ?? TEST_DEFAULTS.FLOW_THREAD_ID,
83
+ __retries: options?.retries ?? 0,
84
+ _shadowing: options?.shadowing,
85
+ _hubtype_case_id: options?.hubtypeCaseId,
86
+ capture_user_input: options?.captureUserInputNodeId ? {
87
+ node_id: options.captureUserInputNodeId
88
+ } : undefined
89
+ };
90
+ }
91
+ function createTestInput(options) {
92
+ return {
93
+ type: options?.type ?? INPUT.TEXT,
94
+ data: options?.data,
95
+ text: options?.text ?? options?.data,
96
+ payload: options?.payload,
97
+ src: options?.src,
98
+ transcript: options?.transcript,
99
+ context: options?.context,
100
+ bot_interaction_id: options?.botInteractionId ?? TEST_DEFAULTS.BOT_INTERACTION_ID,
101
+ message_id: options?.messageId ?? TEST_DEFAULTS.MESSAGE_ID
102
+ };
103
+ }
104
+ function isFullInput(v) {
105
+ return 'bot_interaction_id' in v && 'message_id' in v;
106
+ }
107
+ function isFullSession(v) {
108
+ return 'bot' in v && '__retries' in v;
109
+ }
110
+ function isFullSettings(v) {
111
+ return 'HUBTYPE_API_URL' in v && 'STATIC_URL' in v && 'LITELLM_API_URL' in v && 'AZURE_OPENAI_API_BASE' in v && 'AZURE_OPENAI_API_VERSION' in v && 'LANGUAGE_DETECTION_ENABLED' in v && 'CUSTOM_SHORT_URL_HOST' in v && 'custom' in v;
112
+ }
113
+ function isFullSecrets(v) {
114
+ return 'HUBTYPE_ACCESS_TOKEN' in v && 'LITELLM_API_KEY' in v && 'AZURE_OPENAI_API_KEY' in v && 'custom' in v;
115
+ }
116
+ function createTestBotRequest(options) {
117
+ const input = options?.input == null ? createTestInput() : isFullInput(options.input) ? options.input : createTestInput(options.input);
118
+ const session = options?.session == null ? createTestSession() : isFullSession(options.session) ? options.session : createTestSession(options.session);
119
+ const settings = options?.settings == null ? createTestSettings() : isFullSettings(options.settings) ? options.settings : createTestSettings(options.settings);
120
+ const secrets = options?.secrets == null ? createTestSecrets() : isFullSecrets(options.secrets) ? options.secrets : createTestSecrets(options.secrets);
121
+ return {
122
+ input,
123
+ session,
124
+ lastRoutePath: options?.lastRoutePath ?? TEST_DEFAULTS.LAST_ROUTE_PATH,
125
+ settings,
126
+ secrets
127
+ };
128
+ }
129
+ function createTestBotContext(options) {
130
+ const request = createTestBotRequest(options);
131
+ const sessionForLocale = options?.session == null ? createTestSession() : isFullSession(options.session) ? options.session : createTestSession(options.session);
132
+ const locale = sessionForLocale.user.locale;
133
+ const country = sessionForLocale.user.country;
134
+ const systemLocale = sessionForLocale.user.system_locale;
135
+ return {
136
+ ...request,
137
+ plugins: options?.plugins ?? {},
138
+ params: options?.params ?? {},
139
+ defaultDelay: options?.defaultDelay ?? 0,
140
+ defaultTyping: options?.defaultTyping ?? 0,
141
+ getUserLocale: ()=>locale,
142
+ getUserCountry: ()=>country,
143
+ getSystemLocale: ()=>systemLocale,
144
+ setUserLocale: ()=>undefined,
145
+ setUserCountry: ()=>undefined,
146
+ setSystemLocale: ()=>undefined
147
+ };
148
+ }
149
+ /**
150
+ * Alias for `createTestBotContext` typed as `PluginPreRequest`.
151
+ * PluginPreRequest === BotContext in @botonic/core.
152
+ */ const createTestPluginPreRequest = createTestBotContext;
153
+ function createTestPluginPostRequest(options) {
154
+ return {
155
+ ...createTestBotContext(options),
156
+ response: options?.response ?? null
157
+ };
158
+ }
159
+
160
+ export { TEST_DEFAULTS, createTestBotContext, createTestBotRequest, createTestInput, createTestPluginPostRequest, createTestPluginPreRequest, createTestSecrets, createTestSession, createTestSessionUser, createTestSettings };
161
+
162
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing/index.js","sources":["../../src/testing/index.ts"],"sourcesContent":["import {\n type BotContext,\n type BotRequest,\n type BotSecrets,\n type BotSettings,\n type ContactInfo,\n INPUT,\n type Input,\n PROVIDER,\n type ProviderType,\n type ResolvedPlugins,\n type Session,\n type SessionUser,\n} from '../models'\n\n// ---------------------------------------------------------------------------\n// Default values\n// ---------------------------------------------------------------------------\n\nexport const TEST_DEFAULTS = {\n HUBTYPE_API_URL: 'https://api.hubtype.com',\n STATIC_URL: 'https://static.hubtype.com',\n LITELLM_API_URL: 'https://api.litellm.com',\n AZURE_OPENAI_API_BASE: 'https://api.openai.com',\n AZURE_OPENAI_API_VERSION: '2026-02-01',\n LANGUAGE_DETECTION_ENABLED: true,\n HUBTYPE_ACCESS_TOKEN: 'testAccessToken', // pragma: allowlist secret\n LITELLM_API_KEY: 'testLiteLLMAPIKey', // pragma: allowlist secret\n AZURE_OPENAI_API_KEY: 'testAzureOpenAIAPIKey', // pragma: allowlist secret\n ACCESS_TOKEN: 'fake_access_token',\n HUBTYPE_API_HOST: 'https://api.hubtype.com',\n FLOW_THREAD_ID: 'testFlowThreadId',\n BOT_ID: 'testBotId',\n USER_ID: 'testUserId',\n ORG_ID: 'testOrgId',\n ORG_NAME: 'testOrg',\n PROVIDER: PROVIDER.WEBCHAT as ProviderType,\n LOCALE: 'en',\n COUNTRY: 'US',\n BOT_INTERACTION_ID: 'testInteractionId',\n MESSAGE_ID: 'testMessageId',\n LAST_ROUTE_PATH: '',\n}\n\n// ---------------------------------------------------------------------------\n// Leaf factories\n// ---------------------------------------------------------------------------\n\nexport function createTestSettings(\n overrides?: Partial<BotSettings>\n): BotSettings {\n return {\n HUBTYPE_API_URL: TEST_DEFAULTS.HUBTYPE_API_URL,\n STATIC_URL: TEST_DEFAULTS.STATIC_URL,\n LITELLM_API_URL: TEST_DEFAULTS.LITELLM_API_URL,\n AZURE_OPENAI_API_BASE: TEST_DEFAULTS.AZURE_OPENAI_API_BASE,\n AZURE_OPENAI_API_VERSION: TEST_DEFAULTS.AZURE_OPENAI_API_VERSION,\n LANGUAGE_DETECTION_ENABLED: TEST_DEFAULTS.LANGUAGE_DETECTION_ENABLED,\n CUSTOM_SHORT_URL_HOST: null,\n custom: {},\n ...overrides,\n }\n}\n\nexport function createTestSecrets(overrides?: Partial<BotSecrets>): BotSecrets {\n return {\n HUBTYPE_ACCESS_TOKEN: TEST_DEFAULTS.HUBTYPE_ACCESS_TOKEN,\n LITELLM_API_KEY: TEST_DEFAULTS.LITELLM_API_KEY,\n AZURE_OPENAI_API_KEY: TEST_DEFAULTS.AZURE_OPENAI_API_KEY,\n custom: {},\n ...overrides,\n }\n}\n\nexport interface TestUserOptions {\n id?: string\n provider?: ProviderType\n locale?: string\n country?: string\n systemLocale?: string\n contactInfo?: ContactInfo[]\n extraData?: Record<string, any>\n}\n\nexport function createTestSessionUser(\n options?: TestUserOptions\n): SessionUser<Record<string, any>> {\n const locale = options?.locale ?? TEST_DEFAULTS.LOCALE\n const country = options?.country ?? TEST_DEFAULTS.COUNTRY\n return {\n id: options?.id ?? TEST_DEFAULTS.USER_ID,\n provider: options?.provider ?? TEST_DEFAULTS.PROVIDER,\n locale,\n country,\n system_locale: options?.systemLocale ?? locale,\n contact_info: options?.contactInfo ?? [],\n extra_data: options?.extraData ?? {},\n }\n}\n\nexport interface TestSessionOptions {\n user?: TestUserOptions\n botId?: string\n organization?: string\n organizationId?: string\n isFirstInteraction?: boolean\n isTestIntegration?: boolean\n accessToken?: string\n hubtypeApi?: string\n flowThreadId?: string\n retries?: number\n shadowing?: boolean\n hubtypeCaseId?: string\n captureUserInputNodeId?: string\n}\n\nexport function createTestSession(\n options?: TestSessionOptions\n): Session<Record<string, any>> {\n return {\n bot: { id: options?.botId ?? TEST_DEFAULTS.BOT_ID },\n user: createTestSessionUser(options?.user),\n organization: options?.organization ?? TEST_DEFAULTS.ORG_NAME,\n organization_id: options?.organizationId ?? TEST_DEFAULTS.ORG_ID,\n is_first_interaction: options?.isFirstInteraction ?? false,\n is_test_integration: options?.isTestIntegration ?? false,\n _access_token: options?.accessToken ?? TEST_DEFAULTS.ACCESS_TOKEN,\n _hubtype_api: options?.hubtypeApi ?? TEST_DEFAULTS.HUBTYPE_API_HOST,\n flow_thread_id: options?.flowThreadId ?? TEST_DEFAULTS.FLOW_THREAD_ID,\n __retries: options?.retries ?? 0,\n _shadowing: options?.shadowing,\n _hubtype_case_id: options?.hubtypeCaseId,\n capture_user_input: options?.captureUserInputNodeId\n ? { node_id: options.captureUserInputNodeId }\n : undefined,\n }\n}\n\nexport interface TestInputOptions {\n type?: Input['type']\n data?: string\n text?: string\n payload?: string\n src?: string\n botInteractionId?: string\n messageId?: string\n context?: Input['context']\n transcript?: string\n}\n\nexport function createTestInput(options?: TestInputOptions): Input {\n return {\n type: options?.type ?? INPUT.TEXT,\n data: options?.data,\n text: options?.text ?? options?.data,\n payload: options?.payload,\n src: options?.src,\n transcript: options?.transcript,\n context: options?.context,\n bot_interaction_id:\n options?.botInteractionId ?? TEST_DEFAULTS.BOT_INTERACTION_ID,\n message_id: options?.messageId ?? TEST_DEFAULTS.MESSAGE_ID,\n }\n}\n\n// ---------------------------------------------------------------------------\n// Composite factories\n// ---------------------------------------------------------------------------\n\nexport interface TestBotRequestOptions {\n input?: TestInputOptions | Input\n session?: TestSessionOptions | Session\n lastRoutePath?: string\n settings?: Partial<BotSettings> | BotSettings\n secrets?: Partial<BotSecrets> | BotSecrets\n}\n\nfunction isFullInput(v: TestInputOptions | Input): v is Input {\n return 'bot_interaction_id' in v && 'message_id' in v\n}\n\nfunction isFullSession(v: TestSessionOptions | Session): v is Session {\n return 'bot' in v && '__retries' in v\n}\n\nfunction isFullSettings(\n v: Partial<BotSettings> | BotSettings\n): v is BotSettings {\n return (\n 'HUBTYPE_API_URL' in v &&\n 'STATIC_URL' in v &&\n 'LITELLM_API_URL' in v &&\n 'AZURE_OPENAI_API_BASE' in v &&\n 'AZURE_OPENAI_API_VERSION' in v &&\n 'LANGUAGE_DETECTION_ENABLED' in v &&\n 'CUSTOM_SHORT_URL_HOST' in v &&\n 'custom' in v\n )\n}\n\nfunction isFullSecrets(v: Partial<BotSecrets> | BotSecrets): v is BotSecrets {\n return (\n 'HUBTYPE_ACCESS_TOKEN' in v &&\n 'LITELLM_API_KEY' in v &&\n 'AZURE_OPENAI_API_KEY' in v &&\n 'custom' in v\n )\n}\n\nexport function createTestBotRequest(\n options?: TestBotRequestOptions\n): BotRequest {\n const input =\n options?.input == null\n ? createTestInput()\n : isFullInput(options.input)\n ? options.input\n : createTestInput(options.input)\n\n const session =\n options?.session == null\n ? createTestSession()\n : isFullSession(options.session)\n ? options.session\n : createTestSession(options.session)\n\n const settings =\n options?.settings == null\n ? createTestSettings()\n : isFullSettings(options.settings)\n ? options.settings\n : createTestSettings(options.settings)\n\n const secrets =\n options?.secrets == null\n ? createTestSecrets()\n : isFullSecrets(options.secrets)\n ? options.secrets\n : createTestSecrets(options.secrets)\n\n return {\n input,\n session,\n lastRoutePath: options?.lastRoutePath ?? TEST_DEFAULTS.LAST_ROUTE_PATH,\n settings,\n secrets,\n }\n}\n\nexport interface TestBotContextOptions<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n> extends TestBotRequestOptions {\n plugins?: TPlugins\n params?: Record<string, string>\n defaultDelay?: number\n defaultTyping?: number\n}\n\nexport function createTestBotContext<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n>(options?: TestBotContextOptions<TPlugins>): BotContext<TPlugins> {\n const request = createTestBotRequest(options)\n\n const sessionForLocale =\n options?.session == null\n ? createTestSession()\n : isFullSession(options.session)\n ? options.session\n : createTestSession(options.session)\n\n const locale = sessionForLocale.user.locale\n const country = sessionForLocale.user.country\n const systemLocale = sessionForLocale.user.system_locale\n\n return {\n ...request,\n plugins: options?.plugins ?? ({} as TPlugins),\n params: options?.params ?? {},\n defaultDelay: options?.defaultDelay ?? 0,\n defaultTyping: options?.defaultTyping ?? 0,\n getUserLocale: () => locale,\n getUserCountry: () => country,\n getSystemLocale: () => systemLocale,\n setUserLocale: () => undefined,\n setUserCountry: () => undefined,\n setSystemLocale: () => undefined,\n }\n}\n\n/**\n * Alias for `createTestBotContext` typed as `PluginPreRequest`.\n * PluginPreRequest === BotContext in @botonic/core.\n */\nexport const createTestPluginPreRequest = createTestBotContext\n\nexport interface TestPluginPostRequestOptions<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n> extends TestBotContextOptions<TPlugins> {\n response?: string | null\n}\n\nexport function createTestPluginPostRequest<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n>(\n options?: TestPluginPostRequestOptions<TPlugins>\n): BotContext<TPlugins> & { response: string | null } {\n return {\n ...createTestBotContext(options),\n response: options?.response ?? null,\n }\n}\n"],"names":["INPUT","PROVIDER","TEST_DEFAULTS","createTestSettings","overrides","createTestSecrets","createTestSessionUser","options","locale","country","createTestSession","undefined","createTestInput","isFullInput","v","isFullSession","isFullSettings","isFullSecrets","createTestBotRequest","input","session","settings","secrets","createTestBotContext","request","sessionForLocale","systemLocale","createTestPluginPreRequest","createTestPluginPostRequest"],"mappings":";;;AAakB;AAElB,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAEvE,MAAME,aAAaA,GAAG;IAC3B,iBAAiB;IACjB,YAAY;IACZ,iBAAiB;IACjB,uBAAuB;IACvB,0BAA0B;IAC1B,4BAA4B;IAC5B,sBAAsB;IACtB,iBAAiB;IACjB,sBAAsB;IACtB,cAAc;IACd,kBAAkB;IAClB,gBAAgB;IAChB,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,UAAU;IACV,UAAUD,gBAAgB;IAC1B,QAAQ;IACR,SAAS;IACT,oBAAoB;IACpB,YAAY;IACZ,iBAAiB;AACnB,EAAC;AAED,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAEvE,SAASE,kBAAkBA,CAChCC,SAAgC;IAEhC,OAAO;QACL,iBAAiBF,aAAaA,CAAC,eAAe;QAC9C,YAAYA,aAAaA,CAAC,UAAU;QACpC,iBAAiBA,aAAaA,CAAC,eAAe;QAC9C,uBAAuBA,aAAaA,CAAC,qBAAqB;QAC1D,0BAA0BA,aAAaA,CAAC,wBAAwB;QAChE,4BAA4BA,aAAaA,CAAC,0BAA0B;QACpE,uBAAuB;QACvB,QAAQ,CAAC;QACT,GAAGE,SAAS;IACd;AACF;AAEO,SAASC,iBAAiBA,CAACD,SAA+B;IAC/D,OAAO;QACL,sBAAsBF,aAAaA,CAAC,oBAAoB;QACxD,iBAAiBA,aAAaA,CAAC,eAAe;QAC9C,sBAAsBA,aAAaA,CAAC,oBAAoB;QACxD,QAAQ,CAAC;QACT,GAAGE,SAAS;IACd;AACF;AAYO,SAASE,qBAAqBA,CACnCC,OAAyB;IAEzB,MAAMC,SAASD,SAAS,UAAUL,aAAaA,CAAC,MAAM;IACtD,MAAMO,UAAUF,SAAS,WAAWL,aAAaA,CAAC,OAAO;IACzD,OAAO;QACL,IAAIK,SAAS,MAAML,aAAaA,CAAC,O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MAAMhB,UAAUgB,iBAAiB,IAAI,CAAC,OAAO;IAC7C,MAAMC,eAAeD,iBAAiB,IAAI,CAAC,aAAa;IAExD,OAAO;QACL,GAAGD,OAAO;QACV,SAASjB,SAAS,WAAY,CAAC;QAC/B,QAAQA,SAAS,UAAU,CAAC;QAC5B,cAAcA,SAAS,gBAAgB;QACvC,eAAeA,SAAS,iBAAiB;QACzC,eAAe,IAAMC;QACrB,gBAAgB,IAAMC;QACtB,iBAAiB,IAAMiB;QACvB,eAAe,IAAMf;QACrB,gBAAgB,IAAMA;QACtB,iBAAiB,IAAMA;IACzB;AACF;AAEA;;;CAGC,GACM,MAAMgB,0BAA0BA,GAAGJ,oBAAoBA,CAAA;AAQvD,SAASK,2BAA2BA,CAGzCrB,OAAgD;IAEhD,OAAO;QACL,GAAGgB,oBAAoBA,CAAChB,QAAQ;QAChC,UAAUA,SAAS,YAAY;IACjC;AACF"}
@@ -1,4 +1,4 @@
1
1
  import { type ZodType } from 'zod';
2
- import { type VariableConfigJSON } from '../models/index';
2
+ import { type VariableConfigJSON } from '../models/index.js';
3
3
  export declare const BASE_SESSION_VARIABLES: VariableConfigJSON[];
4
4
  export declare function getSessionVariables(extraDataSchema?: ZodType): VariableConfigJSON[];