@botonic/core 0.43.0 → 0.44.0-alpha.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 (62) hide show
  1. package/lib/cjs/core-bot.js +83 -91
  2. package/lib/cjs/core-bot.js.map +1 -1
  3. package/lib/cjs/debug/inspector.js.map +1 -1
  4. package/lib/cjs/handoff.js +124 -140
  5. package/lib/cjs/handoff.js.map +1 -1
  6. package/lib/cjs/hubtype-service.js +36 -35
  7. package/lib/cjs/hubtype-service.js.map +1 -1
  8. package/lib/cjs/models/hubtype-analytics.d.ts +12 -4
  9. package/lib/cjs/models/hubtype-analytics.js +4 -3
  10. package/lib/cjs/models/hubtype-analytics.js.map +1 -1
  11. package/lib/cjs/models/legacy-types.d.ts +3 -0
  12. package/lib/cjs/models/legacy-types.js +7 -7
  13. package/lib/cjs/models/legacy-types.js.map +1 -1
  14. package/lib/cjs/plugins.js +17 -18
  15. package/lib/cjs/plugins.js.map +1 -1
  16. package/lib/cjs/pusher-utils.js +1 -2
  17. package/lib/cjs/pusher-utils.js.map +1 -1
  18. package/lib/cjs/routing/router-utils.js +19 -22
  19. package/lib/cjs/routing/router-utils.js.map +1 -1
  20. package/lib/cjs/routing/router.js +20 -16
  21. package/lib/cjs/routing/router.js.map +1 -1
  22. package/lib/cjs/utils.js +12 -13
  23. package/lib/cjs/utils.js.map +1 -1
  24. package/lib/esm/constants.js +7 -4
  25. package/lib/esm/constants.js.map +1 -1
  26. package/lib/esm/core-bot.js +94 -98
  27. package/lib/esm/core-bot.js.map +1 -1
  28. package/lib/esm/debug/index.js +4 -1
  29. package/lib/esm/debug/index.js.map +1 -1
  30. package/lib/esm/debug/inspector.js +11 -4
  31. package/lib/esm/debug/inspector.js.map +1 -1
  32. package/lib/esm/handoff.js +139 -143
  33. package/lib/esm/handoff.js.map +1 -1
  34. package/lib/esm/hubtype-service.js +46 -41
  35. package/lib/esm/hubtype-service.js.map +1 -1
  36. package/lib/esm/index.js +12 -9
  37. package/lib/esm/index.js.map +1 -1
  38. package/lib/esm/models/ai-agents.js +2 -1
  39. package/lib/esm/models/hubtype-analytics.d.ts +12 -4
  40. package/lib/esm/models/hubtype-analytics.js +11 -7
  41. package/lib/esm/models/hubtype-analytics.js.map +1 -1
  42. package/lib/esm/models/index.js +7 -4
  43. package/lib/esm/models/index.js.map +1 -1
  44. package/lib/esm/models/knowledge-bases.js +2 -1
  45. package/lib/esm/models/legacy-types.d.ts +3 -0
  46. package/lib/esm/models/legacy-types.js +17 -14
  47. package/lib/esm/models/legacy-types.js.map +1 -1
  48. package/lib/esm/plugins.js +19 -16
  49. package/lib/esm/plugins.js.map +1 -1
  50. package/lib/esm/pusher-utils.js +6 -3
  51. package/lib/esm/pusher-utils.js.map +1 -1
  52. package/lib/esm/routing/index.js +5 -2
  53. package/lib/esm/routing/index.js.map +1 -1
  54. package/lib/esm/routing/router-utils.js +35 -28
  55. package/lib/esm/routing/router-utils.js.map +1 -1
  56. package/lib/esm/routing/router.js +45 -37
  57. package/lib/esm/routing/router.js.map +1 -1
  58. package/lib/esm/utils.js +44 -27
  59. package/lib/esm/utils.js.map +1 -1
  60. package/package.json +2 -2
  61. package/src/models/hubtype-analytics.ts +11 -3
  62. package/src/models/legacy-types.ts +3 -0
@@ -1,5 +1,8 @@
1
- export const EVENT_FORMAT_VERSION = 5;
2
- export var EventAction;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebviewEndFailType = exports.KnowledgebaseFailReason = exports.EventAction = exports.EVENT_FORMAT_VERSION = void 0;
4
+ exports.EVENT_FORMAT_VERSION = 5;
5
+ var EventAction;
3
6
  (function (EventAction) {
4
7
  EventAction["AiAgent"] = "ai_agent";
5
8
  EventAction["FeedbackCase"] = "feedback_case";
@@ -25,16 +28,17 @@ export var EventAction;
25
28
  EventAction["WebviewEnd"] = "webview_end";
26
29
  EventAction["Custom"] = "custom";
27
30
  EventAction["RedirectFlow"] = "redirect_flow";
28
- })(EventAction || (EventAction = {}));
29
- export var KnowledgebaseFailReason;
31
+ EventAction["CaptureUserInput"] = "capture_user_input";
32
+ })(EventAction || (exports.EventAction = EventAction = {}));
33
+ var KnowledgebaseFailReason;
30
34
  (function (KnowledgebaseFailReason) {
31
35
  KnowledgebaseFailReason["NoKnowledge"] = "no_knowledge";
32
36
  KnowledgebaseFailReason["Hallucination"] = "hallucination";
33
- })(KnowledgebaseFailReason || (KnowledgebaseFailReason = {}));
34
- export var WebviewEndFailType;
37
+ })(KnowledgebaseFailReason || (exports.KnowledgebaseFailReason = KnowledgebaseFailReason = {}));
38
+ var WebviewEndFailType;
35
39
  (function (WebviewEndFailType) {
36
40
  WebviewEndFailType["CanceledByUser"] = "canceled_by_user";
37
41
  WebviewEndFailType["ApiError"] = "api_error";
38
42
  WebviewEndFailType["NeedsEscalation"] = "needs_escalation";
39
- })(WebviewEndFailType || (WebviewEndFailType = {}));
43
+ })(WebviewEndFailType || (exports.WebviewEndFailType = WebviewEndFailType = {}));
40
44
  //# sourceMappingURL=hubtype-analytics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hubtype-analytics.js","sourceRoot":"","sources":["../../../src/models/hubtype-analytics.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AAErC,MAAM,CAAN,IAAY,WAyBX;AAzBD,WAAY,WAAW;IACrB,mCAAoB,CAAA;IACpB,6CAA8B,CAAA;IAC9B,mDAAoC,CAAA;IACpC,6DAA8C,CAAA;IAC9C,+DAAgD,CAAA;IAChD,mDAAoC,CAAA;IACpC,qCAAsB,CAAA;IACtB,yDAA0C,CAAA;IAC1C,kEAAmD,CAAA;IACnD,uDAAwC,CAAA;IACxC,yDAA0C,CAAA;IAC1C,uCAAwB,CAAA;IACxB,kEAAmD,CAAA;IACnD,+CAAgC,CAAA;IAChC,iDAAkC,CAAA;IAClC,2CAA4B,CAAA;IAC5B,sCAAuB,CAAA;IACvB,+CAAgC,CAAA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GX;AAHD,WAAY,uBAAuB;IACjC,uDAA4B,CAAA;IAC5B,0DAA+B,CAAA;AACjC,CAAC,EAHW,uBAAuB,uCAAvB,uBAAuB,QAGlC;AA8ED,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,yDAAmC,CAAA;IACnC,4CAAsB,CAAA;IACtB,0DAAoC,CAAA;AACtC,CAAC,EAJW,kBAAkB,kCAAlB,kBAAkB,QAI7B"}
@@ -1,5 +1,8 @@
1
- export * from './ai-agents';
2
- export * from './hubtype-analytics';
3
- export * from './knowledge-bases';
4
- export * from './legacy-types';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./ai-agents"), exports);
5
+ tslib_1.__exportStar(require("./hubtype-analytics"), exports);
6
+ tslib_1.__exportStar(require("./knowledge-bases"), exports);
7
+ tslib_1.__exportStar(require("./legacy-types"), exports);
5
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":";;;AAAA,sDAA2B;AAC3B,8DAAmC;AACnC,4DAAiC;AACjC,yDAA8B"}
@@ -1,2 +1,3 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
2
3
  //# sourceMappingURL=knowledge-bases.js.map
@@ -205,6 +205,9 @@ export interface Session<TExtraData = any> {
205
205
  path: string;
206
206
  active: boolean;
207
207
  };
208
+ capture_user_input?: {
209
+ node_id: string;
210
+ };
208
211
  }
209
212
  export type InputMatcher = (input: Input) => boolean;
210
213
  export type ParamsMatcher = {
@@ -1,19 +1,22 @@
1
+ "use strict";
1
2
  // TODO: This file contains all the legacy types we had in index.ts. After some refactors, we should be able to get rid of many of them.
2
- export var CASE_STATUS;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.BotonicAction = exports.CaseStatus = exports.NluType = exports.INPUT = exports.PROVIDER = exports.CASE_RESOLUTION = exports.CASE_STATUS = void 0;
5
+ var CASE_STATUS;
3
6
  (function (CASE_STATUS) {
4
7
  CASE_STATUS["WAITING"] = "status_waiting";
5
8
  CASE_STATUS["ATTENDING"] = "status_attending";
6
9
  CASE_STATUS["IDLE"] = "status_idle";
7
10
  CASE_STATUS["RESOLVED"] = "status_resolved";
8
- })(CASE_STATUS || (CASE_STATUS = {}));
9
- export var CASE_RESOLUTION;
11
+ })(CASE_STATUS || (exports.CASE_STATUS = CASE_STATUS = {}));
12
+ var CASE_RESOLUTION;
10
13
  (function (CASE_RESOLUTION) {
11
14
  CASE_RESOLUTION["OK"] = "result_ok";
12
15
  CASE_RESOLUTION["NOK"] = "result_nok";
13
16
  CASE_RESOLUTION["NOT_SOLVED"] = "result_not_solved";
14
17
  CASE_RESOLUTION["BANNED"] = "result_banned";
15
- })(CASE_RESOLUTION || (CASE_RESOLUTION = {}));
16
- export var PROVIDER;
18
+ })(CASE_RESOLUTION || (exports.CASE_RESOLUTION = CASE_RESOLUTION = {}));
19
+ var PROVIDER;
17
20
  (function (PROVIDER) {
18
21
  PROVIDER["APPLE"] = "apple";
19
22
  PROVIDER["DEV"] = "dev";
@@ -27,8 +30,8 @@ export var PROVIDER;
27
30
  PROVIDER["WEBCHAT"] = "webchat";
28
31
  PROVIDER["WECHAT"] = "wechat";
29
32
  PROVIDER["WHATSAPP"] = "whatsapp";
30
- })(PROVIDER || (PROVIDER = {}));
31
- export var INPUT;
33
+ })(PROVIDER || (exports.PROVIDER = PROVIDER = {}));
34
+ var INPUT;
32
35
  (function (INPUT) {
33
36
  INPUT["TEXT"] = "text";
34
37
  INPUT["POSTBACK"] = "postback";
@@ -57,24 +60,24 @@ export var INPUT;
57
60
  INPUT["EVENT_QUEUE_POSITION_CHANGED"] = "case_event_queue_position_changed";
58
61
  INPUT["EVENT_CASE_STATUS_CHANGED"] = "case_event_status_changed";
59
62
  INPUT["SYSTEM_DEBUG_TRACE"] = "system_debug_trace";
60
- })(INPUT || (INPUT = {}));
61
- export var NluType;
63
+ })(INPUT || (exports.INPUT = INPUT = {}));
64
+ var NluType;
62
65
  (function (NluType) {
63
66
  NluType["Keyword"] = "keyword";
64
67
  NluType["SmartIntent"] = "smart-intent";
65
- })(NluType || (NluType = {}));
66
- export var CaseStatus;
68
+ })(NluType || (exports.NluType = NluType = {}));
69
+ var CaseStatus;
67
70
  (function (CaseStatus) {
68
71
  CaseStatus["Waiting"] = "status_waiting";
69
72
  CaseStatus["Attending"] = "status_attending";
70
73
  CaseStatus["Idle"] = "status_idle";
71
74
  CaseStatus["Resolved"] = "status_resolved";
72
- })(CaseStatus || (CaseStatus = {}));
73
- export var BotonicAction;
75
+ })(CaseStatus || (exports.CaseStatus = CaseStatus = {}));
76
+ var BotonicAction;
74
77
  (function (BotonicAction) {
75
78
  BotonicAction["Redirect"] = "redirect_action";
76
79
  BotonicAction["CreateCase"] = "create_case";
77
80
  BotonicAction["DeleteUser"] = "delete_user";
78
81
  BotonicAction["DiscardCase"] = "discard_case";
79
- })(BotonicAction || (BotonicAction = {}));
82
+ })(BotonicAction || (exports.BotonicAction = BotonicAction = {}));
80
83
  //# sourceMappingURL=legacy-types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"legacy-types.js","sourceRoot":"","sources":["../../../src/models/legacy-types.ts"],"names":[],"mappings":"AAAA,wIAAwI;AAExI,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,yCAA0B,CAAA;IAC1B,6CAA8B,CAAA;IAC9B,mCAAoB,CAAA;IACpB,2CAA4B,CAAA;AAC9B,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAQD,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,e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AGlB;AAsCD,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,wCAA0B,CAAA;IAC1B,4CAA8B,CAAA;IAC9B,kCAAoB,CAAA;IACpB,0CAA4B,CAAA;AAC9B,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AA6PD,MAAM,CAAN,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,6CAA4B,CAAA;IAC5B,2CAA0B,CAAA;IAC1B,2CAA0B,CAAA;IAC1B,6CAA4B,CAAA;AAC9B,CAAC,EALW,aAAa,KAAb,aAAa,QAKxB"}
1
+ {"version":3,"file":"legacy-types.js","sourceRoot":"","sources":["../../../src/models/legacy-types.ts"],"names":[],"mappings":";AAAA,wIAAwI;;;AAExI,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,yCAA0B,CAAA;IAC1B,6CAA8B,CAAA;IAC9B,mCAAoB,CAAA;IACpB,2CAA4B,CAAA;AAC9B,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAQD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,mCAAgB,CAAA;IAChB,qCAAkB,CAAA;IAClB,mDAAgC,CAAA;IAChC,2CAAwB,CAAA;AAC1B,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B;AAQD,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,uBAAW,CAAA;IACX,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,iCAAqB,CAAA;IACrB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;AACvB,CAAC,EAbW,QAAQ,wBAAR,QAAQ,QAanB;AAeD,IAAY,KA4BX;AA5BD,WAAY,KAAK;IACf,sBAAa,CAAA;IACb,8BAAqB,CAAA;IACrB,wBAAe,CAAA;IACf,wBAAe,CAAA;IACf,wBAAe,CAAA;IACf,8BAAqB,CAAA;IACrB,8BAAqB,CAAA;IACrB,4BAAmB,CAAA;IACnB,yCAAgC,CAAA;IAChC,8BAAqB,CAAA;IACrB,0BAAiB,CAAA;IACjB,6CAAoC,CAAA;IACpC,+CAAsC,CAAA;IACtC,oBAAW,CAAA;IACX,iCAAwB,CAAA;IACxB,sDAA6C,CAAA;IAC7C,4DAAmD,CAAA;IACnD,8CAAqC,CAAA;IACrC,8CAAqC,CAAA;IACrC,wDAA+C,CAAA;IAC/C,gEAAuD,CAAA;IACvD,4DAAmD,CAAA;IACnD,0CAAiC,CAAA;IACjC,yEAAgE,CAAA;IAChE,2EAAkE,CAAA;IAClE,gEAAuD,CAAA;IACvD,kDAAyC,CAAA;AAC3C,CAAC,EA5BW,KAAK,qBAAL,KAAK,QA4BhB;AA8CD,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,8BAAmB,CAAA;IACnB,uCAA4B,CAAA;AAC9B,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAsCD,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,wCAA0B,CAAA;IAC1B,4CAA8B,CAAA;IAC9B,kCAAoB,CAAA;IACpB,0CAA4B,CAAA;AAC9B,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAgQD,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,6CAA4B,CAAA;IAC5B,2CAA0B,CAAA;IAC1B,2CAA0B,CAAA;IAC1B,6CAA4B,CAAA;AAC9B,CAAC,EALW,aAAa,6BAAb,aAAa,QAKxB"}
@@ -1,21 +1,24 @@
1
- import { __awaiter } from "tslib";
2
- export function runPlugins({ botContext, mode, response = null, }) {
3
- return __awaiter(this, void 0, void 0, function* () {
4
- const plugins = botContext.plugins;
5
- for (const key in plugins) {
6
- const plugin = plugins[key];
7
- try {
8
- if (mode === 'pre' && typeof plugin.pre === 'function') {
9
- yield plugin.pre(botContext);
10
- }
11
- if (mode === 'post' && typeof plugin.post === 'function') {
12
- yield plugin.post(Object.assign(Object.assign({}, botContext), { response }));
13
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runPlugins = runPlugins;
4
+ async function runPlugins({ botContext, mode, response = null, }) {
5
+ const plugins = botContext.plugins;
6
+ for (const key in plugins) {
7
+ const plugin = plugins[key];
8
+ try {
9
+ if (mode === 'pre' && typeof plugin.pre === 'function') {
10
+ await plugin.pre(botContext);
14
11
  }
15
- catch (e) {
16
- console.log(e);
12
+ if (mode === 'post' && typeof plugin.post === 'function') {
13
+ await plugin.post({
14
+ ...botContext,
15
+ response,
16
+ });
17
17
  }
18
18
  }
19
- });
19
+ catch (e) {
20
+ console.log(e);
21
+ }
22
+ }
20
23
  }
21
24
  //# sourceMappingURL=plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/plugins.ts"],"names":[],"mappings":";AAUA,MAAM,UAAgB,UAAU,CAAC,EAC/B,UAAU,EACV,IAAI,EACJ,QAAQ,GAAG,IAAI,GACD;;QACd,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;QAClC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;YACzB,MAAM,MAAM,GAAW,OAAO,CAAC,GAAG,CAAC,CAAA;YACnC,IAAI;gBACF,IAAI,IAAI,KAAK,KAAK,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,UAAU,EAAE;oBACtD,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;iBAC7B;gBACD,IAAI,IAAI,KAAK,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE;oBACxD,MAAM,MAAM,CAAC,IAAI,iCACZ,UAAU,KACb,QAAQ,IACR,CAAA;iBACH;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;aACf;SACF;IACH,CAAC;CAAA"}
1
+ {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/plugins.ts"],"names":[],"mappings":";;AAUA,gCAsBC;AAtBM,KAAK,UAAU,UAAU,CAAC,EAC/B,UAAU,EACV,IAAI,EACJ,QAAQ,GAAG,IAAI,GACD;IACd,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;IAClC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAW,OAAO,CAAC,GAAG,CAAC,CAAA;QACnC,IAAI,CAAC;YACH,IAAI,IAAI,KAAK,KAAK,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;gBACvD,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;YAC9B,CAAC;YACD,IAAI,IAAI,KAAK,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACzD,MAAM,MAAM,CAAC,IAAI,CAAC;oBAChB,GAAG,UAAU;oBACb,QAAQ;iBACT,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,15 +1,18 @@
1
- import { inflate } from 'pako';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decompressData = decompressData;
4
+ const pako_1 = require("pako");
2
5
  /**
3
6
  *
4
7
  * @param compressedData a string representing gzipped data previously encoded to base64 for very large contents
5
8
  * @returns a string representing the information of a very large content
6
9
  * Ref: https://stackoverflow.com/questions/4875020/javascript-decompress-inflate-unzip-ungzip-strings (check jsfiddle proposal)
7
10
  */
8
- export function decompressData(compressedData) {
11
+ function decompressData(compressedData) {
9
12
  const strData = atob(compressedData); // Decode base64 (convert ascii to binary)
10
13
  const charData = strData.split('').map(x => x.charCodeAt(0)); // Convert binary string to character-number array
11
14
  const binData = new Uint8Array(charData); // Turn number array into byte-array
12
- const data = inflate(binData);
15
+ const data = (0, pako_1.inflate)(binData);
13
16
  // @ts-ignore
14
17
  return String.fromCharCode.apply(null, new Uint8Array(data)); // Convert gunzipped byteArray back to ascii string
15
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pusher-utils.js","sourceRoot":"","sources":["../../src/pusher-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,cAAsB;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,CAAA,CAAC,0CAA0C;IAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,kDAAkD;IAC/G,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAA,CAAC,oCAAoC;IAC7E,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,aAAa;IACb,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,mDAAmD;AAClH,CAAC"}
1
+ {"version":3,"file":"pusher-utils.js","sourceRoot":"","sources":["../../src/pusher-utils.ts"],"names":[],"mappings":";;AAQA,wCAOC;AAfD,+BAA8B;AAE9B;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,cAAsB;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,CAAA,CAAC,0CAA0C;IAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,kDAAkD;IAC/G,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAA,CAAC,oCAAoC;IAC7E,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,OAAO,CAAC,CAAA;IAC7B,aAAa;IACb,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,mDAAmD;AAClH,CAAC"}
@@ -1,3 +1,6 @@
1
- export * from './router';
2
- export * from './router-utils';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./router"), exports);
5
+ tslib_1.__exportStar(require("./router-utils"), exports);
3
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,yDAA8B"}
@@ -1,18 +1,27 @@
1
- import { __awaiter } from "tslib";
2
- import { EMPTY_ACTION_PATH, NOT_FOUND_PATH, PATH_PAYLOAD_IDENTIFIER, PATH_PAYLOAD_REGEXP, } from '../constants';
3
- export class NoMatchingRouteError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoMatchingRouteError = void 0;
4
+ exports.isPathPayload = isPathPayload;
5
+ exports.getPathParamsFromPathPayload = getPathParamsFromPathPayload;
6
+ exports.pathParamsToParams = pathParamsToParams;
7
+ exports.getEmptyAction = getEmptyAction;
8
+ exports.getNotFoundAction = getNotFoundAction;
9
+ exports.getComputedRoutes = getComputedRoutes;
10
+ const constants_1 = require("../constants");
11
+ class NoMatchingRouteError extends Error {
4
12
  constructor(input) {
5
- super(`No route found for input '${JSON.stringify(input)}' and no ${NOT_FOUND_PATH} route defined`);
13
+ super(`No route found for input '${JSON.stringify(input)}' and no ${constants_1.NOT_FOUND_PATH} route defined`);
6
14
  this.input = input;
7
15
  }
8
16
  }
9
- export function isPathPayload(payload) {
17
+ exports.NoMatchingRouteError = NoMatchingRouteError;
18
+ function isPathPayload(payload) {
10
19
  if (!payload)
11
20
  return false;
12
- const isPathPayload = PATH_PAYLOAD_REGEXP.exec(payload);
21
+ const isPathPayload = constants_1.PATH_PAYLOAD_REGEXP.exec(payload);
13
22
  return Boolean(isPathPayload);
14
23
  }
15
- export function getPathParamsFromPathPayload(payload) {
24
+ function getPathParamsFromPathPayload(payload) {
16
25
  const defaultPathParams = {
17
26
  path: null,
18
27
  params: {},
@@ -22,19 +31,19 @@ export function getPathParamsFromPathPayload(payload) {
22
31
  if (!isPathPayload(payload))
23
32
  return defaultPathParams;
24
33
  try {
25
- const pathWithParams = payload.split(PATH_PAYLOAD_IDENTIFIER)[1];
34
+ const pathWithParams = payload.split(constants_1.PATH_PAYLOAD_IDENTIFIER)[1];
26
35
  if (!pathWithParams) {
27
- throw `${PATH_PAYLOAD_IDENTIFIER} is empty`;
36
+ throw `${constants_1.PATH_PAYLOAD_IDENTIFIER} is empty`;
28
37
  }
29
38
  const [path, params] = pathWithParams.split('?');
30
- return { path: path !== null && path !== void 0 ? path : null, params: pathParamsToParams(params) };
39
+ return { path: path ?? null, params: pathParamsToParams(params) };
31
40
  }
32
41
  catch (e) {
33
42
  console.error('Error getting path and params from input.payload:', e);
34
43
  return defaultPathParams;
35
44
  }
36
45
  }
37
- export function pathParamsToParams(pathParams) {
46
+ function pathParamsToParams(pathParams) {
38
47
  if (!pathParams)
39
48
  return {};
40
49
  try {
@@ -49,34 +58,32 @@ export function pathParamsToParams(pathParams) {
49
58
  return {};
50
59
  }
51
60
  }
52
- export function getEmptyAction(childRoutes) {
61
+ function getEmptyAction(childRoutes) {
53
62
  if (!childRoutes)
54
63
  return null;
55
- const emptyActionRoute = childRoutes.find(r => r.path === EMPTY_ACTION_PATH);
64
+ const emptyActionRoute = childRoutes.find(r => r.path === constants_1.EMPTY_ACTION_PATH);
56
65
  if (!emptyActionRoute)
57
66
  return null;
58
67
  return emptyActionRoute.action;
59
68
  }
60
- export function getNotFoundAction(input, routes) {
61
- const notFoundActionRoute = routes.find(r => r.path === NOT_FOUND_PATH);
69
+ function getNotFoundAction(input, routes) {
70
+ const notFoundActionRoute = routes.find(r => r.path === constants_1.NOT_FOUND_PATH);
62
71
  if (!notFoundActionRoute)
63
72
  throw new NoMatchingRouteError(input);
64
73
  return notFoundActionRoute.action;
65
74
  }
66
- export function getComputedRoutes(routes, botContext) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- if (routes instanceof Function) {
69
- return yield getComputedRoutes(yield routes(botContext), botContext);
75
+ async function getComputedRoutes(routes, botContext) {
76
+ if (routes instanceof Function) {
77
+ return await getComputedRoutes(await routes(botContext), botContext);
78
+ }
79
+ for (const [key, route] of Object.entries(routes)) {
80
+ if (route.childRoutes && route.childRoutes instanceof Function) {
81
+ routes[key].childRoutes = await getComputedRoutes(await route.childRoutes(botContext), botContext);
70
82
  }
71
- for (const [key, route] of Object.entries(routes)) {
72
- if (route.childRoutes && route.childRoutes instanceof Function) {
73
- routes[key].childRoutes = yield getComputedRoutes(yield route.childRoutes(botContext), botContext);
74
- }
75
- else {
76
- routes[key] = route;
77
- }
83
+ else {
84
+ routes[key] = route;
78
85
  }
79
- return routes;
80
- });
86
+ }
87
+ return routes;
81
88
  }
82
89
  //# sourceMappingURL=router-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router-utils.js","sourceRoot":"","sources":["../../../src/routing/router-utils.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,cAAc,CAAA;AAWrB,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAE7C,YAAY,KAAY;QACtB,KAAK,CACH,6BAA6B,IA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,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,0BAAc,CAAC,CAAA;IACvE,IAAI,CAAC,mBAAmB;QAAE,MAAM,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAA;IAC/D,OAAO,mBAAmB,CAAC,MAAM,CAAA;AACnC,CAAC;AAEM,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,UAAsB;IAEtB,IAAI,MAAM,YAAY,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,iBAAiB,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAA;IACtE,CAAC;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAQ,EAAE,CAAC;QACzD,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,YAAY,QAAQ,EAAE,CAAC;YAC/D,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,GAAG,MAAM,iBAAiB,CAC/C,MAAM,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,EACnC,UAAU,CACX,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACrB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -1,11 +1,14 @@
1
- import { NOT_FOUND_PATH } from '../constants';
2
- import { RouteInspector } from '../debug/inspector';
3
- import { cloneObject } from '../utils';
4
- import { getEmptyAction, getNotFoundAction, getPathParamsFromPathPayload, isPathPayload, } from './router-utils';
5
- export class Router {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Router = void 0;
4
+ const constants_1 = require("../constants");
5
+ const inspector_1 = require("../debug/inspector");
6
+ const utils_1 = require("../utils");
7
+ const router_utils_1 = require("./router-utils");
8
+ class Router {
6
9
  constructor(routes, routeInspector = undefined) {
7
10
  this.routes = routes;
8
- this.routeInspector = routeInspector || new RouteInspector();
11
+ this.routeInspector = routeInspector || new inspector_1.RouteInspector();
9
12
  }
10
13
  /**
11
14
  * Processes an input and return a representation of the new bot state.
@@ -19,12 +22,11 @@ export class Router {
19
22
  */
20
23
  // eslint-disable-next-line complexity
21
24
  processInput(input, session, lastRoutePath = null) {
22
- var _a, _b, _c, _d, _e;
23
- session.__retries = (_a = session === null || session === void 0 ? void 0 : session.__retries) !== null && _a !== void 0 ? _a : 0;
25
+ session.__retries = session?.__retries ?? 0;
24
26
  // 1. Getting the current routing state.
25
27
  const { currentRoute, matchedRoute, params, isFlowBroken } = this.getRoutingState(input, session, lastRoutePath);
26
- const currentRoutePath = (_b = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) !== null && _b !== void 0 ? _b : null;
27
- const matchedRoutePath = (_c = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.path) !== null && _c !== void 0 ? _c : null;
28
+ const currentRoutePath = currentRoute?.path ?? null;
29
+ const matchedRoutePath = matchedRoute?.path ?? null;
28
30
  // 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
29
31
  /**
30
32
  * Redirect Scenario:
@@ -38,7 +40,7 @@ export class Router {
38
40
  if (redirectionRoute) {
39
41
  return {
40
42
  action: redirectionRoute.action,
41
- emptyAction: getEmptyAction(redirectionRoute.childRoutes),
43
+ emptyAction: (0, router_utils_1.getEmptyAction)(redirectionRoute.childRoutes),
42
44
  fallbackAction: null,
43
45
  lastRoutePath: matchedRoute.redirect,
44
46
  params,
@@ -47,7 +49,7 @@ export class Router {
47
49
  return {
48
50
  action: null,
49
51
  emptyAction: null,
50
- fallbackAction: getNotFoundAction(input, this.routes),
52
+ fallbackAction: (0, router_utils_1.getNotFoundAction)(input, this.routes),
51
53
  lastRoutePath: null,
52
54
  params,
53
55
  };
@@ -60,7 +62,7 @@ export class Router {
60
62
  session.__retries = 0;
61
63
  return {
62
64
  action: matchedRoute.action,
63
- emptyAction: getEmptyAction(matchedRoute.childRoutes),
65
+ emptyAction: (0, router_utils_1.getEmptyAction)(matchedRoute.childRoutes),
64
66
  fallbackAction: null,
65
67
  lastRoutePath: matchedRoutePath,
66
68
  params,
@@ -76,19 +78,19 @@ export class Router {
76
78
  currentRoute.retry &&
77
79
  session.__retries < currentRoute.retry) {
78
80
  session.__retries = session.__retries !== 0 ? session.__retries + 1 : 1;
79
- if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {
81
+ if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
80
82
  return {
81
83
  action: currentRoute.action,
82
- emptyAction: getEmptyAction(matchedRoute.childRoutes),
84
+ emptyAction: (0, router_utils_1.getEmptyAction)(matchedRoute.childRoutes),
83
85
  fallbackAction: matchedRoute.action,
84
86
  lastRoutePath: currentRoutePath,
85
87
  params,
86
88
  };
87
89
  }
88
90
  return {
89
- action: (_d = currentRoute.action) !== null && _d !== void 0 ? _d : null,
90
- emptyAction: getEmptyAction(currentRoute.childRoutes),
91
- fallbackAction: getNotFoundAction(input, this.routes),
91
+ action: currentRoute.action ?? null,
92
+ emptyAction: (0, router_utils_1.getEmptyAction)(currentRoute.childRoutes),
93
+ fallbackAction: (0, router_utils_1.getNotFoundAction)(input, this.routes),
92
94
  lastRoutePath: currentRoutePath,
93
95
  params,
94
96
  };
@@ -102,10 +104,10 @@ export class Router {
102
104
  * Matching Route Scenario:
103
105
  * We have matched a route, so we return the new bot state.
104
106
  */
105
- if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {
107
+ if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
106
108
  return {
107
- action: (_e = matchedRoute.action) !== null && _e !== void 0 ? _e : null,
108
- emptyAction: getEmptyAction(matchedRoute.childRoutes),
109
+ action: matchedRoute.action ?? null,
110
+ emptyAction: (0, router_utils_1.getEmptyAction)(matchedRoute.childRoutes),
109
111
  fallbackAction: null,
110
112
  lastRoutePath: matchedRoutePath,
111
113
  params,
@@ -118,7 +120,7 @@ export class Router {
118
120
  return {
119
121
  action: null,
120
122
  emptyAction: null,
121
- fallbackAction: getNotFoundAction(input, this.routes),
123
+ fallbackAction: (0, router_utils_1.getNotFoundAction)(input, this.routes),
122
124
  params,
123
125
  lastRoutePath: currentRoutePath,
124
126
  };
@@ -136,14 +138,14 @@ export class Router {
136
138
  try {
137
139
  if (match !== null && typeof match !== 'boolean' && match.groups) {
138
140
  // Strip '[Object: null prototype]' from groups result: https://stackoverflow.com/a/62945609/6237608
139
- params = Object.assign({}, match.groups);
141
+ params = { ...match.groups };
140
142
  }
141
143
  }
142
144
  catch (e) { }
143
145
  return Boolean(match);
144
146
  }));
145
147
  if (route)
146
- return { route: cloneObject(route), params };
148
+ return { route: (0, utils_1.cloneObject)(route), params };
147
149
  return null;
148
150
  }
149
151
  /**
@@ -164,10 +166,10 @@ export class Router {
164
166
  const computedRoute = this.getRouteByPath(childPath.join('/'), route.childRoutes);
165
167
  // IMPORTANT: Returning a new object to avoid modifying dev routes and introduce side effects
166
168
  if (computedRoute)
167
- return cloneObject(computedRoute);
169
+ return (0, utils_1.cloneObject)(computedRoute);
168
170
  }
169
171
  else if (childPath.length === 0) {
170
- return cloneObject(route); // last action and found route
172
+ return (0, utils_1.cloneObject)(route); // last action and found route
171
173
  }
172
174
  }
173
175
  }
@@ -225,7 +227,7 @@ export class Router {
225
227
  const currentRoute = this.getRouteByPath(lastRoutePath);
226
228
  if (currentRoute && lastRoutePath)
227
229
  currentRoute.path = lastRoutePath;
228
- if (typeof input.payload === 'string' && isPathPayload(input.payload)) {
230
+ if (typeof input.payload === 'string' && (0, router_utils_1.isPathPayload)(input.payload)) {
229
231
  return this.getRoutingStateFromPathPayload(currentRoute, input.payload);
230
232
  }
231
233
  return this.getRoutingStateFromInput(currentRoute, input, session);
@@ -234,16 +236,18 @@ export class Router {
234
236
  * 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.
235
237
  * */
236
238
  getRoutingStateFromInput(currentRoute, input, session) {
237
- var _a, _b, _c;
238
239
  // get route depending of current ChildRoutes
239
240
  if (currentRoute && currentRoute.childRoutes) {
240
241
  const routeParams = this.getRoute(input, currentRoute.childRoutes, session, currentRoute.path);
241
242
  if (routeParams) {
242
243
  return {
243
244
  currentRoute,
244
- matchedRoute: Object.assign(Object.assign({}, routeParams.route), { path: routeParams.route && currentRoute.path
245
+ matchedRoute: {
246
+ ...routeParams.route,
247
+ path: routeParams.route && currentRoute.path
245
248
  ? `${currentRoute.path}/${routeParams.route.path}`
246
- : currentRoute.path }),
249
+ : currentRoute.path,
250
+ },
247
251
  params: routeParams.params,
248
252
  isFlowBroken: false,
249
253
  };
@@ -253,12 +257,15 @@ export class Router {
253
257
  * we couldn't find a route in the state of the currentRoute childRoutes,
254
258
  * so let's find in the general routes
255
259
  */
256
- const routeParams = this.getRoute(input, this.routes, session, (_a = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) !== null && _a !== void 0 ? _a : null);
257
- const isFlowBroken = Boolean(currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path);
258
- if (routeParams === null || routeParams === void 0 ? void 0 : routeParams.route) {
260
+ const routeParams = this.getRoute(input, this.routes, session, currentRoute?.path ?? null);
261
+ const isFlowBroken = Boolean(currentRoute?.path);
262
+ if (routeParams?.route) {
259
263
  return {
260
264
  currentRoute,
261
- matchedRoute: Object.assign(Object.assign({}, routeParams.route), { path: (_c = (_b = routeParams.route) === null || _b === void 0 ? void 0 : _b.path) !== null && _c !== void 0 ? _c : null }),
265
+ matchedRoute: {
266
+ ...routeParams.route,
267
+ path: routeParams.route?.path ?? null,
268
+ },
262
269
  params: routeParams.params,
263
270
  isFlowBroken,
264
271
  };
@@ -274,7 +281,7 @@ export class Router {
274
281
  * 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.
275
282
  * */
276
283
  getRoutingStateFromPathPayload(currentRoute, pathPayload) {
277
- const { path, params } = getPathParamsFromPathPayload(pathPayload);
284
+ const { path, params } = (0, router_utils_1.getPathParamsFromPathPayload)(pathPayload);
278
285
  /**
279
286
  * shorthand function to update the matching information given a path
280
287
  */
@@ -290,7 +297,7 @@ export class Router {
290
297
  }
291
298
  return {
292
299
  currentRoute,
293
- matchedRoute: Object.assign(Object.assign({}, matchedRoute), { path: seekPath }),
300
+ matchedRoute: { ...matchedRoute, path: seekPath },
294
301
  params,
295
302
  isFlowBroken: false,
296
303
  };
@@ -299,7 +306,7 @@ export class Router {
299
306
  * Given a valid path: 'Flow1/Subflow1' we are in one of the two scenarios below.
300
307
  */
301
308
  // 1. Received __PATH_PAYLOAD__Subflow2, so we need to first try to concatenate it with Flow1 (lastRoutePath)
302
- if (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) {
309
+ if (currentRoute?.path) {
303
310
  const routingState = getRoutingStateFromPath(`${currentRoute.path}/${path}`);
304
311
  if (routingState.matchedRoute)
305
312
  return routingState;
@@ -308,4 +315,5 @@ export class Router {
308
315
  return getRoutingStateFromPath(path);
309
316
  }
310
317
  }
318
+ exports.Router = Router;
311
319
  //# sourceMappingURL=router.js.map