@wabot-dev/framework 0.0.17 → 0.0.50

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 (110) hide show
  1. package/dist/src/_virtual/_commonjsHelpers.js +5 -0
  2. package/dist/src/_virtual/cjs.js +7 -0
  3. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +12 -13
  4. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +9 -7
  5. package/dist/src/channels/cmd/@cmd.js +0 -4
  6. package/dist/src/channels/cmd/CmdChannel.js +0 -4
  7. package/dist/src/channels/express/ExpressProvider.js +46 -0
  8. package/dist/src/channels/http/HttpServerProvider.js +31 -0
  9. package/dist/src/channels/{socket-io → socket}/@socket.js +0 -4
  10. package/dist/src/channels/{socket-io → socket}/SocketChannel.js +12 -11
  11. package/dist/src/channels/socket/SocketServerProvider.js +50 -0
  12. package/dist/src/channels/telegram/@telegram.js +0 -4
  13. package/dist/src/channels/telegram/TelegramChannel.js +0 -4
  14. package/dist/src/channels/wabot/WabotDevConnection.js +57 -0
  15. package/dist/src/channels/{whatsapp/WhatsAppDevSocketContracts.js → wabot/WabotDevSocketContracts.js} +3 -3
  16. package/dist/src/channels/whatsapp/@whatsapp.js +0 -4
  17. package/dist/src/channels/whatsapp/EnvWhatsAppRepository.js +49 -0
  18. package/dist/src/channels/whatsapp/PgWhatsAppRepository.js +41 -0
  19. package/dist/src/channels/whatsapp/WhatsApp.js +32 -0
  20. package/dist/src/channels/whatsapp/WhatsAppChannel.js +33 -32
  21. package/dist/src/channels/whatsapp/{WhatsAppConnection.js → WhatsAppReceiver.js} +4 -6
  22. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +32 -0
  23. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +63 -0
  24. package/dist/src/channels/whatsapp/WhatsAppRepository.js +10 -0
  25. package/dist/src/channels/whatsapp/WhatsAppSender.js +93 -17
  26. package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +124 -0
  27. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +61 -0
  28. package/dist/src/chatbot/ChatBotAdapter.js +1 -5
  29. package/dist/src/chatbot/metadata/@chatBot.js +0 -5
  30. package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +0 -5
  31. package/dist/src/controller/metadata/ControllerMetadataStore.js +0 -2
  32. package/dist/src/controller/metadata/controller/@chatController.js +0 -2
  33. package/dist/src/core/IMessageContext.js +0 -2
  34. package/dist/src/env/WabotEnv.js +6 -0
  35. package/dist/src/index.d.ts +419 -201
  36. package/dist/src/index.js +55 -28
  37. package/dist/src/mindset/MindsetOperator.js +1 -3
  38. package/dist/src/mindset/metadata/MindsetMetadataStore.js +0 -2
  39. package/dist/src/mindset/metadata/mindsets/@mindset.js +0 -2
  40. package/dist/src/mindset/metadata/modules/@mindsetModule.js +0 -2
  41. package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +90 -0
  42. package/dist/src/node_modules/deepmerge/dist/cjs.js +142 -0
  43. package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +102 -0
  44. package/dist/src/node_modules/dom-serializer/lib/esm/index.js +186 -0
  45. package/dist/src/node_modules/domelementtype/lib/esm/index.js +53 -0
  46. package/dist/src/node_modules/domhandler/lib/esm/index.js +148 -0
  47. package/dist/src/node_modules/domhandler/lib/esm/node.js +334 -0
  48. package/dist/src/node_modules/entities/lib/esm/decode.js +458 -0
  49. package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +62 -0
  50. package/dist/src/node_modules/entities/lib/esm/escape.js +99 -0
  51. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +8 -0
  52. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +8 -0
  53. package/dist/src/node_modules/html-to-text/lib/html-to-text.js +2147 -0
  54. package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +491 -0
  55. package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +928 -0
  56. package/dist/src/node_modules/htmlparser2/lib/esm/index.js +18 -0
  57. package/dist/src/node_modules/leac/lib/leac.js +3 -0
  58. package/dist/src/node_modules/parseley/lib/parseley.js +270 -0
  59. package/dist/src/node_modules/peberminta/lib/core.js +171 -0
  60. package/dist/src/node_modules/selderee/lib/selderee.js +380 -0
  61. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -2
  62. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -2
  63. package/dist/src/pre-made/module/html/HtmlModule.js +70 -0
  64. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -2
  65. package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +1 -7
  66. package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +0 -5
  67. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -5
  68. package/dist/src/repository/pg/PgCrudRepository.js +0 -1
  69. package/dist/src/rest-controller/metadata/@get.js +19 -0
  70. package/dist/src/rest-controller/metadata/@post.js +19 -0
  71. package/dist/src/rest-controller/metadata/@restController.js +15 -0
  72. package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +37 -0
  73. package/dist/src/rest-controller/runRestControllers.js +74 -0
  74. package/dist/src/server/prepareChatContainer.js +4 -4
  75. package/dist/src/server/runChannel.js +2 -10
  76. package/dist/src/server/runServer.js +0 -43
  77. package/dist/src/validation/metadata/@isBoolean.js +17 -0
  78. package/dist/src/validation/metadata/@isDate.js +17 -0
  79. package/dist/src/validation/metadata/@isNotEmpty.js +17 -0
  80. package/dist/src/validation/metadata/@isNumber.js +17 -0
  81. package/dist/src/validation/metadata/@isOptional.js +17 -0
  82. package/dist/src/validation/metadata/@isPresent.js +17 -0
  83. package/dist/src/validation/metadata/@isString.js +17 -0
  84. package/dist/src/validation/metadata/@max.js +18 -0
  85. package/dist/src/validation/metadata/@min.js +18 -0
  86. package/dist/src/validation/metadata/@validable.js +14 -0
  87. package/dist/src/validation/metadata/ValidationMetadataStore.js +55 -0
  88. package/dist/src/validation/validateModel2.js +11 -0
  89. package/dist/src/validation/validators/validateIsBoolean.js +12 -0
  90. package/dist/src/validation/validators/validateIsDate.js +16 -0
  91. package/dist/src/validation/validators/validateIsNotEmpty.js +12 -0
  92. package/dist/src/validation/validators/validateIsNumber.js +12 -0
  93. package/dist/src/validation/validators/validateIsOptional.js +5 -0
  94. package/dist/src/validation/validators/validateIsPresent.js +12 -0
  95. package/dist/src/validation/validators/validateIsString.js +12 -0
  96. package/dist/src/validation/validators/validateMax.js +17 -0
  97. package/dist/src/validation/validators/validateMin.js +17 -0
  98. package/dist/src/validation/validators/validateModel.js +47 -0
  99. package/package.json +4 -6
  100. package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +0 -69
  101. package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +0 -39
  102. package/dist/src/controller/express/Express.js +0 -5
  103. package/dist/src/controller/socket.io/SocketIO.js +0 -5
  104. package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
  105. package/dist/src/pre-made/repository/chat/sqlite/SqliteChatMemory.js +0 -23
  106. package/dist/src/pre-made/repository/chat/sqlite/SqliteChatRepository.js +0 -30
  107. package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +0 -23
  108. package/dist/src/repository/sqlite/SqliteCrudRepository.js +0 -85
  109. package/dist/src/repository/sqlite/SqlitePersistentMapper.js +0 -17
  110. /package/dist/src/channels/{socket-io → socket}/SocketChannelConfig.js +0 -0
@@ -0,0 +1,186 @@
1
+ import { Text, Tag, Style, Script, CDATA, Comment, Directive, Doctype, Root } from '../../../domelementtype/lib/esm/index.js';
2
+ import { elementNames, attributeNames } from './foreignNames.js';
3
+ import { encodeXML, escapeText, escapeAttribute } from '../../../entities/lib/esm/escape.js';
4
+
5
+ /*
6
+ * Module dependencies
7
+ */
8
+ const unencodedElements = new Set([
9
+ "style",
10
+ "script",
11
+ "xmp",
12
+ "iframe",
13
+ "noembed",
14
+ "noframes",
15
+ "plaintext",
16
+ "noscript",
17
+ ]);
18
+ function replaceQuotes(value) {
19
+ return value.replace(/"/g, """);
20
+ }
21
+ /**
22
+ * Format attributes
23
+ */
24
+ function formatAttributes(attributes, opts) {
25
+ var _a;
26
+ if (!attributes)
27
+ return;
28
+ const encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false
29
+ ? replaceQuotes
30
+ : opts.xmlMode || opts.encodeEntities !== "utf8"
31
+ ? encodeXML
32
+ : escapeAttribute;
33
+ return Object.keys(attributes)
34
+ .map((key) => {
35
+ var _a, _b;
36
+ const value = (_a = attributes[key]) !== null && _a !== void 0 ? _a : "";
37
+ if (opts.xmlMode === "foreign") {
38
+ /* Fix up mixed-case attribute names */
39
+ key = (_b = attributeNames.get(key)) !== null && _b !== void 0 ? _b : key;
40
+ }
41
+ if (!opts.emptyAttrs && !opts.xmlMode && value === "") {
42
+ return key;
43
+ }
44
+ return `${key}="${encode(value)}"`;
45
+ })
46
+ .join(" ");
47
+ }
48
+ /**
49
+ * Self-enclosing tags
50
+ */
51
+ const singleTag = new Set([
52
+ "area",
53
+ "base",
54
+ "basefont",
55
+ "br",
56
+ "col",
57
+ "command",
58
+ "embed",
59
+ "frame",
60
+ "hr",
61
+ "img",
62
+ "input",
63
+ "isindex",
64
+ "keygen",
65
+ "link",
66
+ "meta",
67
+ "param",
68
+ "source",
69
+ "track",
70
+ "wbr",
71
+ ]);
72
+ /**
73
+ * Renders a DOM node or an array of DOM nodes to a string.
74
+ *
75
+ * Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
76
+ *
77
+ * @param node Node to be rendered.
78
+ * @param options Changes serialization behavior
79
+ */
80
+ function render(node, options = {}) {
81
+ const nodes = "length" in node ? node : [node];
82
+ let output = "";
83
+ for (let i = 0; i < nodes.length; i++) {
84
+ output += renderNode(nodes[i], options);
85
+ }
86
+ return output;
87
+ }
88
+ function renderNode(node, options) {
89
+ switch (node.type) {
90
+ case Root:
91
+ return render(node.children, options);
92
+ // @ts-expect-error We don't use `Doctype` yet
93
+ case Doctype:
94
+ case Directive:
95
+ return renderDirective(node);
96
+ case Comment:
97
+ return renderComment(node);
98
+ case CDATA:
99
+ return renderCdata(node);
100
+ case Script:
101
+ case Style:
102
+ case Tag:
103
+ return renderTag(node, options);
104
+ case Text:
105
+ return renderText(node, options);
106
+ }
107
+ }
108
+ const foreignModeIntegrationPoints = new Set([
109
+ "mi",
110
+ "mo",
111
+ "mn",
112
+ "ms",
113
+ "mtext",
114
+ "annotation-xml",
115
+ "foreignObject",
116
+ "desc",
117
+ "title",
118
+ ]);
119
+ const foreignElements = new Set(["svg", "math"]);
120
+ function renderTag(elem, opts) {
121
+ var _a;
122
+ // Handle SVG / MathML in HTML
123
+ if (opts.xmlMode === "foreign") {
124
+ /* Fix up mixed-case element names */
125
+ elem.name = (_a = elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name;
126
+ /* Exit foreign mode at integration points */
127
+ if (elem.parent &&
128
+ foreignModeIntegrationPoints.has(elem.parent.name)) {
129
+ opts = { ...opts, xmlMode: false };
130
+ }
131
+ }
132
+ if (!opts.xmlMode && foreignElements.has(elem.name)) {
133
+ opts = { ...opts, xmlMode: "foreign" };
134
+ }
135
+ let tag = `<${elem.name}`;
136
+ const attribs = formatAttributes(elem.attribs, opts);
137
+ if (attribs) {
138
+ tag += ` ${attribs}`;
139
+ }
140
+ if (elem.children.length === 0 &&
141
+ (opts.xmlMode
142
+ ? // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags
143
+ opts.selfClosingTags !== false
144
+ : // User explicitly asked for self-closing tags, even in HTML mode
145
+ opts.selfClosingTags && singleTag.has(elem.name))) {
146
+ if (!opts.xmlMode)
147
+ tag += " ";
148
+ tag += "/>";
149
+ }
150
+ else {
151
+ tag += ">";
152
+ if (elem.children.length > 0) {
153
+ tag += render(elem.children, opts);
154
+ }
155
+ if (opts.xmlMode || !singleTag.has(elem.name)) {
156
+ tag += `</${elem.name}>`;
157
+ }
158
+ }
159
+ return tag;
160
+ }
161
+ function renderDirective(elem) {
162
+ return `<${elem.data}>`;
163
+ }
164
+ function renderText(elem, opts) {
165
+ var _a;
166
+ let data = elem.data || "";
167
+ // If entities weren't decoded, no need to encode them back
168
+ if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false &&
169
+ !(!opts.xmlMode &&
170
+ elem.parent &&
171
+ unencodedElements.has(elem.parent.name))) {
172
+ data =
173
+ opts.xmlMode || opts.encodeEntities !== "utf8"
174
+ ? encodeXML(data)
175
+ : escapeText(data);
176
+ }
177
+ return data;
178
+ }
179
+ function renderCdata(elem) {
180
+ return `<![CDATA[${elem.children[0].data}]]>`;
181
+ }
182
+ function renderComment(elem) {
183
+ return `<!--${elem.data}-->`;
184
+ }
185
+
186
+ export { render as default, render };
@@ -0,0 +1,53 @@
1
+ /** Types of elements found in htmlparser2's DOM */
2
+ var ElementType;
3
+ (function (ElementType) {
4
+ /** Type for the root element of a document */
5
+ ElementType["Root"] = "root";
6
+ /** Type for Text */
7
+ ElementType["Text"] = "text";
8
+ /** Type for <? ... ?> */
9
+ ElementType["Directive"] = "directive";
10
+ /** Type for <!-- ... --> */
11
+ ElementType["Comment"] = "comment";
12
+ /** Type for <script> tags */
13
+ ElementType["Script"] = "script";
14
+ /** Type for <style> tags */
15
+ ElementType["Style"] = "style";
16
+ /** Type for Any tag */
17
+ ElementType["Tag"] = "tag";
18
+ /** Type for <![CDATA[ ... ]]> */
19
+ ElementType["CDATA"] = "cdata";
20
+ /** Type for <!doctype ...> */
21
+ ElementType["Doctype"] = "doctype";
22
+ })(ElementType || (ElementType = {}));
23
+ /**
24
+ * Tests whether an element is a tag or not.
25
+ *
26
+ * @param elem Element to test
27
+ */
28
+ function isTag(elem) {
29
+ return (elem.type === ElementType.Tag ||
30
+ elem.type === ElementType.Script ||
31
+ elem.type === ElementType.Style);
32
+ }
33
+ // Exports for backwards compatibility
34
+ /** Type for the root element of a document */
35
+ const Root = ElementType.Root;
36
+ /** Type for Text */
37
+ const Text = ElementType.Text;
38
+ /** Type for <? ... ?> */
39
+ const Directive = ElementType.Directive;
40
+ /** Type for <!-- ... --> */
41
+ const Comment = ElementType.Comment;
42
+ /** Type for <script> tags */
43
+ const Script = ElementType.Script;
44
+ /** Type for <style> tags */
45
+ const Style = ElementType.Style;
46
+ /** Type for Any tag */
47
+ const Tag = ElementType.Tag;
48
+ /** Type for <![CDATA[ ... ]]> */
49
+ const CDATA = ElementType.CDATA;
50
+ /** Type for <!doctype ...> */
51
+ const Doctype = ElementType.Doctype;
52
+
53
+ export { CDATA, Comment, Directive, Doctype, ElementType, Root, Script, Style, Tag, Text, isTag };
@@ -0,0 +1,148 @@
1
+ import { ElementType } from '../../../domelementtype/lib/esm/index.js';
2
+ import { Document, Element, Text, Comment, CDATA, ProcessingInstruction } from './node.js';
3
+ export { DataNode, Node, NodeWithChildren, cloneNode, isCDATA, isComment, isDirective, isDocument, isTag, isText } from './node.js';
4
+
5
+ // Default options
6
+ const defaultOpts = {
7
+ withStartIndices: false,
8
+ withEndIndices: false,
9
+ xmlMode: false,
10
+ };
11
+ class DomHandler {
12
+ /**
13
+ * @param callback Called once parsing has completed.
14
+ * @param options Settings for the handler.
15
+ * @param elementCB Callback whenever a tag is closed.
16
+ */
17
+ constructor(callback, options, elementCB) {
18
+ /** The elements of the DOM */
19
+ this.dom = [];
20
+ /** The root element for the DOM */
21
+ this.root = new Document(this.dom);
22
+ /** Indicated whether parsing has been completed. */
23
+ this.done = false;
24
+ /** Stack of open tags. */
25
+ this.tagStack = [this.root];
26
+ /** A data node that is still being written to. */
27
+ this.lastNode = null;
28
+ /** Reference to the parser instance. Used for location information. */
29
+ this.parser = null;
30
+ // Make it possible to skip arguments, for backwards-compatibility
31
+ if (typeof options === "function") {
32
+ elementCB = options;
33
+ options = defaultOpts;
34
+ }
35
+ if (typeof callback === "object") {
36
+ options = callback;
37
+ callback = undefined;
38
+ }
39
+ this.callback = callback !== null && callback !== void 0 ? callback : null;
40
+ this.options = options !== null && options !== void 0 ? options : defaultOpts;
41
+ this.elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null;
42
+ }
43
+ onparserinit(parser) {
44
+ this.parser = parser;
45
+ }
46
+ // Resets the handler back to starting state
47
+ onreset() {
48
+ this.dom = [];
49
+ this.root = new Document(this.dom);
50
+ this.done = false;
51
+ this.tagStack = [this.root];
52
+ this.lastNode = null;
53
+ this.parser = null;
54
+ }
55
+ // Signals the handler that parsing is done
56
+ onend() {
57
+ if (this.done)
58
+ return;
59
+ this.done = true;
60
+ this.parser = null;
61
+ this.handleCallback(null);
62
+ }
63
+ onerror(error) {
64
+ this.handleCallback(error);
65
+ }
66
+ onclosetag() {
67
+ this.lastNode = null;
68
+ const elem = this.tagStack.pop();
69
+ if (this.options.withEndIndices) {
70
+ elem.endIndex = this.parser.endIndex;
71
+ }
72
+ if (this.elementCB)
73
+ this.elementCB(elem);
74
+ }
75
+ onopentag(name, attribs) {
76
+ const type = this.options.xmlMode ? ElementType.Tag : undefined;
77
+ const element = new Element(name, attribs, undefined, type);
78
+ this.addNode(element);
79
+ this.tagStack.push(element);
80
+ }
81
+ ontext(data) {
82
+ const { lastNode } = this;
83
+ if (lastNode && lastNode.type === ElementType.Text) {
84
+ lastNode.data += data;
85
+ if (this.options.withEndIndices) {
86
+ lastNode.endIndex = this.parser.endIndex;
87
+ }
88
+ }
89
+ else {
90
+ const node = new Text(data);
91
+ this.addNode(node);
92
+ this.lastNode = node;
93
+ }
94
+ }
95
+ oncomment(data) {
96
+ if (this.lastNode && this.lastNode.type === ElementType.Comment) {
97
+ this.lastNode.data += data;
98
+ return;
99
+ }
100
+ const node = new Comment(data);
101
+ this.addNode(node);
102
+ this.lastNode = node;
103
+ }
104
+ oncommentend() {
105
+ this.lastNode = null;
106
+ }
107
+ oncdatastart() {
108
+ const text = new Text("");
109
+ const node = new CDATA([text]);
110
+ this.addNode(node);
111
+ text.parent = node;
112
+ this.lastNode = text;
113
+ }
114
+ oncdataend() {
115
+ this.lastNode = null;
116
+ }
117
+ onprocessinginstruction(name, data) {
118
+ const node = new ProcessingInstruction(name, data);
119
+ this.addNode(node);
120
+ }
121
+ handleCallback(error) {
122
+ if (typeof this.callback === "function") {
123
+ this.callback(error, this.dom);
124
+ }
125
+ else if (error) {
126
+ throw error;
127
+ }
128
+ }
129
+ addNode(node) {
130
+ const parent = this.tagStack[this.tagStack.length - 1];
131
+ const previousSibling = parent.children[parent.children.length - 1];
132
+ if (this.options.withStartIndices) {
133
+ node.startIndex = this.parser.startIndex;
134
+ }
135
+ if (this.options.withEndIndices) {
136
+ node.endIndex = this.parser.endIndex;
137
+ }
138
+ parent.children.push(node);
139
+ if (previousSibling) {
140
+ node.prev = previousSibling;
141
+ previousSibling.next = node;
142
+ }
143
+ node.parent = parent;
144
+ this.lastNode = null;
145
+ }
146
+ }
147
+
148
+ export { CDATA, Comment, Document, DomHandler, Element, ProcessingInstruction, Text, DomHandler as default };