@wabot-dev/framework 0.1.0-beta.9 → 0.2.0-beta.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 (212) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
  3. package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
  4. package/dist/src/addon/auth/api-key/ApiKey.js +45 -0
  5. package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
  6. package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
  7. package/dist/src/addon/auth/api-key/ApiKeyRepository.js +22 -0
  8. package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +53 -0
  9. package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +62 -0
  10. package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
  11. package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
  12. package/dist/src/addon/auth/jwt/Jwt.js +53 -0
  13. package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  14. package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
  15. package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
  16. package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
  17. package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
  18. package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
  19. package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
  20. package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
  21. package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
  22. package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
  23. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
  24. package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
  25. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
  26. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
  27. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
  28. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  29. package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
  30. package/dist/src/addon/chat-controller/cmd/@cmd.js +24 -0
  31. package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
  32. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
  33. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
  34. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  35. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
  36. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  37. package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -0
  38. package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
  39. package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
  40. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
  41. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  42. package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
  43. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +15 -39
  44. package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
  45. package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +27 -20
  46. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
  47. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
  48. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +61 -0
  49. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
  50. package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +7 -7
  51. package/dist/src/core/auth/Auth.js +33 -0
  52. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
  53. package/dist/src/core/env/Env.js +39 -0
  54. package/dist/src/core/error/CustomError.js +15 -0
  55. package/dist/src/core/injection/index.js +4 -0
  56. package/dist/src/core/mapper/Mapper.js +42 -0
  57. package/dist/src/core/password/Password.js +30 -0
  58. package/dist/src/core/random/Random.js +65 -0
  59. package/dist/src/core/storable/Storable.js +8 -0
  60. package/dist/src/core/validation/core/validateArray.js +51 -0
  61. package/dist/src/core/validation/core/validateModel.js +36 -0
  62. package/dist/src/{validation/metadata/@isNumber.js → core/validation/metadata/@isArray.js} +5 -4
  63. package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
  64. package/dist/src/{validation → core/validation}/metadata/@isOptional.js +1 -1
  65. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  66. package/dist/src/core/validation/modelInfo.js +9 -0
  67. package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
  68. package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js +3 -3
  69. package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
  70. package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
  71. package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
  72. package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
  73. package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
  74. package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
  75. package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
  76. package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
  77. package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
  78. package/dist/src/feature/async/@command.js +11 -0
  79. package/dist/src/feature/async/@commandHandler.js +12 -0
  80. package/dist/src/feature/async/Async.js +38 -0
  81. package/dist/src/feature/async/Command.js +9 -0
  82. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  83. package/dist/src/feature/async/Job.js +27 -0
  84. package/dist/src/feature/async/JobRepository.js +31 -0
  85. package/dist/src/feature/async/JobRunner.js +48 -0
  86. package/dist/src/feature/async/JobsEventsHub.js +36 -0
  87. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  88. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  89. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  90. package/dist/src/feature/chat-bot/ChatBot.js +73 -0
  91. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  92. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  93. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  94. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  95. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  96. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  97. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
  98. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  99. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  100. package/dist/src/feature/chat-controller/runChatControllers.js +83 -0
  101. package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
  102. package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
  103. package/dist/src/{mindset → feature/mindset}/IMindset.js +6 -0
  104. package/dist/src/feature/mindset/MindsetOperator.js +180 -0
  105. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  106. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  107. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  108. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  109. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  110. package/dist/src/feature/money/Money.js +61 -0
  111. package/dist/src/feature/money/MoneyDto.js +22 -0
  112. package/dist/src/{repository → feature}/pg/PgCrudRepository.js +24 -10
  113. package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
  114. package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
  115. package/dist/src/{rest-controller/metadata/@post.js → feature/rest-controller/metadata/@middleware.js} +5 -8
  116. package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
  117. package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
  118. package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
  119. package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
  120. package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
  121. package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
  122. package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
  123. package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
  124. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
  125. package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
  126. package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
  127. package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
  128. package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
  129. package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
  130. package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
  131. package/dist/src/index.d.ts +1219 -718
  132. package/dist/src/index.js +147 -102
  133. package/package.json +8 -2
  134. package/dist/src/_virtual/_commonjsHelpers.js +0 -5
  135. package/dist/src/_virtual/cjs.js +0 -7
  136. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
  137. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
  138. package/dist/src/channels/cmd/@cmd.js +0 -18
  139. package/dist/src/channels/cmd/CmdChannel.js +0 -73
  140. package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
  141. package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
  142. package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
  143. package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
  144. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
  145. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
  146. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
  147. package/dist/src/chatbot/ChatBot.js +0 -51
  148. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  149. package/dist/src/controller/channel/UserResolver.js +0 -21
  150. package/dist/src/core/IMessageContext.js +0 -12
  151. package/dist/src/core/chat/ChatItem.js +0 -15
  152. package/dist/src/core/chat/repository/IChatMemory.js +0 -10
  153. package/dist/src/core/user/IUserRepository.js +0 -19
  154. package/dist/src/core/user/User.js +0 -26
  155. package/dist/src/env/WabotEnv.js +0 -27
  156. package/dist/src/injection/index.js +0 -4
  157. package/dist/src/mindset/MindsetOperator.js +0 -101
  158. package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
  159. package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
  160. package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
  161. package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
  162. package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
  163. package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
  164. package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
  165. package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
  166. package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
  167. package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
  168. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
  169. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
  170. package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
  171. package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
  172. package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
  173. package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
  174. package/dist/src/node_modules/leac/lib/leac.js +0 -3
  175. package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
  176. package/dist/src/node_modules/peberminta/lib/core.js +0 -171
  177. package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
  178. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  179. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  180. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  181. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  182. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  183. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  184. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  185. package/dist/src/pre-made/service/EmailService.js +0 -13
  186. package/dist/src/pre-made/service/OtpService.js +0 -14
  187. package/dist/src/rest-controller/runRestControllers.js +0 -74
  188. package/dist/src/server/prepareChatContainer.js +0 -43
  189. package/dist/src/server/runChannel.js +0 -27
  190. package/dist/src/server/runServer.js +0 -40
  191. package/dist/src/validation/metadata/@validable.js +0 -14
  192. package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
  193. package/dist/src/validation/validators/validateModel.js +0 -47
  194. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  195. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  196. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  197. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
  198. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  199. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  200. /package/dist/src/{validation/validators → core/validation/core}/validateIsOptional.js +0 -0
  201. /package/dist/src/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
  202. /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
  203. /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
  204. /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
  205. /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
  206. /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
  207. /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
  208. /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.js +0 -0
  209. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  210. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  211. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  212. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -1,380 +0,0 @@
1
- import { parse1, normalize, compareSpecificity, serialize } from '../../parseley/lib/parseley.js';
2
-
3
- class DecisionTree {
4
- constructor(input) {
5
- this.branches = weave(toAstTerminalPairs(input));
6
- }
7
- build(builder) {
8
- return builder(this.branches);
9
- }
10
- }
11
- function toAstTerminalPairs(array) {
12
- const len = array.length;
13
- const results = new Array(len);
14
- for (let i = 0; i < len; i++) {
15
- const [selectorString, val] = array[i];
16
- const ast = preprocess(parse1(selectorString));
17
- results[i] = {
18
- ast: ast,
19
- terminal: {
20
- type: 'terminal',
21
- valueContainer: { index: i, value: val, specificity: ast.specificity }
22
- }
23
- };
24
- }
25
- return results;
26
- }
27
- function preprocess(ast) {
28
- reduceSelectorVariants(ast);
29
- normalize(ast);
30
- return ast;
31
- }
32
- function reduceSelectorVariants(ast) {
33
- const newList = [];
34
- ast.list.forEach(sel => {
35
- switch (sel.type) {
36
- case 'class':
37
- newList.push({
38
- matcher: '~=',
39
- modifier: null,
40
- name: 'class',
41
- namespace: null,
42
- specificity: sel.specificity,
43
- type: 'attrValue',
44
- value: sel.name,
45
- });
46
- break;
47
- case 'id':
48
- newList.push({
49
- matcher: '=',
50
- modifier: null,
51
- name: 'id',
52
- namespace: null,
53
- specificity: sel.specificity,
54
- type: 'attrValue',
55
- value: sel.name,
56
- });
57
- break;
58
- case 'combinator':
59
- reduceSelectorVariants(sel.left);
60
- newList.push(sel);
61
- break;
62
- case 'universal':
63
- break;
64
- default:
65
- newList.push(sel);
66
- break;
67
- }
68
- });
69
- ast.list = newList;
70
- }
71
- function weave(items) {
72
- const branches = [];
73
- while (items.length) {
74
- const topKind = findTopKey(items, (sel) => true, getSelectorKind);
75
- const { matches, nonmatches, empty } = breakByKind(items, topKind);
76
- items = nonmatches;
77
- if (matches.length) {
78
- branches.push(branchOfKind(topKind, matches));
79
- }
80
- if (empty.length) {
81
- branches.push(...terminate(empty));
82
- }
83
- }
84
- return branches;
85
- }
86
- function terminate(items) {
87
- const results = [];
88
- for (const item of items) {
89
- const terminal = item.terminal;
90
- if (terminal.type === 'terminal') {
91
- results.push(terminal);
92
- }
93
- else {
94
- const { matches, rest } = partition(terminal.cont, (node) => node.type === 'terminal');
95
- matches.forEach((node) => results.push(node));
96
- if (rest.length) {
97
- terminal.cont = rest;
98
- results.push(terminal);
99
- }
100
- }
101
- }
102
- return results;
103
- }
104
- function breakByKind(items, selectedKind) {
105
- const matches = [];
106
- const nonmatches = [];
107
- const empty = [];
108
- for (const item of items) {
109
- const simpsels = item.ast.list;
110
- if (simpsels.length) {
111
- const isMatch = simpsels.some(node => getSelectorKind(node) === selectedKind);
112
- (isMatch ? matches : nonmatches).push(item);
113
- }
114
- else {
115
- empty.push(item);
116
- }
117
- }
118
- return { matches, nonmatches, empty };
119
- }
120
- function getSelectorKind(sel) {
121
- switch (sel.type) {
122
- case 'attrPresence':
123
- return `attrPresence ${sel.name}`;
124
- case 'attrValue':
125
- return `attrValue ${sel.name}`;
126
- case 'combinator':
127
- return `combinator ${sel.combinator}`;
128
- default:
129
- return sel.type;
130
- }
131
- }
132
- function branchOfKind(kind, items) {
133
- if (kind === 'tag') {
134
- return tagNameBranch(items);
135
- }
136
- if (kind.startsWith('attrValue ')) {
137
- return attrValueBranch(kind.substring(10), items);
138
- }
139
- if (kind.startsWith('attrPresence ')) {
140
- return attrPresenceBranch(kind.substring(13), items);
141
- }
142
- if (kind === 'combinator >') {
143
- return combinatorBranch('>', items);
144
- }
145
- if (kind === 'combinator +') {
146
- return combinatorBranch('+', items);
147
- }
148
- throw new Error(`Unsupported selector kind: ${kind}`);
149
- }
150
- function tagNameBranch(items) {
151
- const groups = spliceAndGroup(items, (x) => x.type === 'tag', (x) => x.name);
152
- const variants = Object.entries(groups).map(([name, group]) => ({
153
- type: 'variant',
154
- value: name,
155
- cont: weave(group.items)
156
- }));
157
- return {
158
- type: 'tagName',
159
- variants: variants
160
- };
161
- }
162
- function attrPresenceBranch(name, items) {
163
- for (const item of items) {
164
- spliceSimpleSelector(item, (x) => (x.type === 'attrPresence') && (x.name === name));
165
- }
166
- return {
167
- type: 'attrPresence',
168
- name: name,
169
- cont: weave(items)
170
- };
171
- }
172
- function attrValueBranch(name, items) {
173
- const groups = spliceAndGroup(items, (x) => (x.type === 'attrValue') && (x.name === name), (x) => `${x.matcher} ${x.modifier || ''} ${x.value}`);
174
- const matchers = [];
175
- for (const group of Object.values(groups)) {
176
- const sel = group.oneSimpleSelector;
177
- const predicate = getAttrPredicate(sel);
178
- const continuation = weave(group.items);
179
- matchers.push({
180
- type: 'matcher',
181
- matcher: sel.matcher,
182
- modifier: sel.modifier,
183
- value: sel.value,
184
- predicate: predicate,
185
- cont: continuation
186
- });
187
- }
188
- return {
189
- type: 'attrValue',
190
- name: name,
191
- matchers: matchers
192
- };
193
- }
194
- function getAttrPredicate(sel) {
195
- if (sel.modifier === 'i') {
196
- const expected = sel.value.toLowerCase();
197
- switch (sel.matcher) {
198
- case '=':
199
- return (actual) => expected === actual.toLowerCase();
200
- case '~=':
201
- return (actual) => actual.toLowerCase().split(/[ \t]+/).includes(expected);
202
- case '^=':
203
- return (actual) => actual.toLowerCase().startsWith(expected);
204
- case '$=':
205
- return (actual) => actual.toLowerCase().endsWith(expected);
206
- case '*=':
207
- return (actual) => actual.toLowerCase().includes(expected);
208
- case '|=':
209
- return (actual) => {
210
- const lower = actual.toLowerCase();
211
- return (expected === lower) || (lower.startsWith(expected) && lower[expected.length] === '-');
212
- };
213
- }
214
- }
215
- else {
216
- const expected = sel.value;
217
- switch (sel.matcher) {
218
- case '=':
219
- return (actual) => expected === actual;
220
- case '~=':
221
- return (actual) => actual.split(/[ \t]+/).includes(expected);
222
- case '^=':
223
- return (actual) => actual.startsWith(expected);
224
- case '$=':
225
- return (actual) => actual.endsWith(expected);
226
- case '*=':
227
- return (actual) => actual.includes(expected);
228
- case '|=':
229
- return (actual) => (expected === actual) || (actual.startsWith(expected) && actual[expected.length] === '-');
230
- }
231
- }
232
- }
233
- function combinatorBranch(combinator, items) {
234
- const groups = spliceAndGroup(items, (x) => (x.type === 'combinator') && (x.combinator === combinator), (x) => serialize(x.left));
235
- const leftItems = [];
236
- for (const group of Object.values(groups)) {
237
- const rightCont = weave(group.items);
238
- const leftAst = group.oneSimpleSelector.left;
239
- leftItems.push({
240
- ast: leftAst,
241
- terminal: { type: 'popElement', cont: rightCont }
242
- });
243
- }
244
- return {
245
- type: 'pushElement',
246
- combinator: combinator,
247
- cont: weave(leftItems)
248
- };
249
- }
250
- function spliceAndGroup(items, predicate, keyCallback) {
251
- const groups = {};
252
- while (items.length) {
253
- const bestKey = findTopKey(items, predicate, keyCallback);
254
- const bestKeyPredicate = (sel) => predicate(sel) && keyCallback(sel) === bestKey;
255
- const hasBestKeyPredicate = (item) => item.ast.list.some(bestKeyPredicate);
256
- const { matches, rest } = partition1(items, hasBestKeyPredicate);
257
- let oneSimpleSelector = null;
258
- for (const item of matches) {
259
- const splicedNode = spliceSimpleSelector(item, bestKeyPredicate);
260
- if (!oneSimpleSelector) {
261
- oneSimpleSelector = splicedNode;
262
- }
263
- }
264
- if (oneSimpleSelector == null) {
265
- throw new Error('No simple selector is found.');
266
- }
267
- groups[bestKey] = { oneSimpleSelector: oneSimpleSelector, items: matches };
268
- items = rest;
269
- }
270
- return groups;
271
- }
272
- function spliceSimpleSelector(item, predicate) {
273
- const simpsels = item.ast.list;
274
- const matches = new Array(simpsels.length);
275
- let firstIndex = -1;
276
- for (let i = simpsels.length; i-- > 0;) {
277
- if (predicate(simpsels[i])) {
278
- matches[i] = true;
279
- firstIndex = i;
280
- }
281
- }
282
- if (firstIndex == -1) {
283
- throw new Error(`Couldn't find the required simple selector.`);
284
- }
285
- const result = simpsels[firstIndex];
286
- item.ast.list = simpsels.filter((sel, i) => !matches[i]);
287
- return result;
288
- }
289
- function findTopKey(items, predicate, keyCallback) {
290
- const candidates = {};
291
- for (const item of items) {
292
- const candidates1 = {};
293
- for (const node of item.ast.list.filter(predicate)) {
294
- candidates1[keyCallback(node)] = true;
295
- }
296
- for (const key of Object.keys(candidates1)) {
297
- if (candidates[key]) {
298
- candidates[key]++;
299
- }
300
- else {
301
- candidates[key] = 1;
302
- }
303
- }
304
- }
305
- let topKind = '';
306
- let topCounter = 0;
307
- for (const entry of Object.entries(candidates)) {
308
- if (entry[1] > topCounter) {
309
- topKind = entry[0];
310
- topCounter = entry[1];
311
- }
312
- }
313
- return topKind;
314
- }
315
- function partition(src, predicate) {
316
- const matches = [];
317
- const rest = [];
318
- for (const x of src) {
319
- if (predicate(x)) {
320
- matches.push(x);
321
- }
322
- else {
323
- rest.push(x);
324
- }
325
- }
326
- return { matches, rest };
327
- }
328
- function partition1(src, predicate) {
329
- const matches = [];
330
- const rest = [];
331
- for (const x of src) {
332
- if (predicate(x)) {
333
- matches.push(x);
334
- }
335
- else {
336
- rest.push(x);
337
- }
338
- }
339
- return { matches, rest };
340
- }
341
-
342
- class Picker {
343
- constructor(f) {
344
- this.f = f;
345
- }
346
- pickAll(el) {
347
- return this.f(el);
348
- }
349
- pick1(el, preferFirst = false) {
350
- const results = this.f(el);
351
- const len = results.length;
352
- if (len === 0) {
353
- return null;
354
- }
355
- if (len === 1) {
356
- return results[0].value;
357
- }
358
- const comparator = (preferFirst)
359
- ? comparatorPreferFirst
360
- : comparatorPreferLast;
361
- let result = results[0];
362
- for (let i = 1; i < len; i++) {
363
- const next = results[i];
364
- if (comparator(result, next)) {
365
- result = next;
366
- }
367
- }
368
- return result.value;
369
- }
370
- }
371
- function comparatorPreferFirst(acc, next) {
372
- const diff = compareSpecificity(next.specificity, acc.specificity);
373
- return diff > 0 || (diff === 0 && next.index < acc.index);
374
- }
375
- function comparatorPreferLast(acc, next) {
376
- const diff = compareSpecificity(next.specificity, acc.specificity);
377
- return diff > 0 || (diff === 0 && next.index > acc.index);
378
- }
379
-
380
- export { DecisionTree, Picker };
@@ -1,97 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../../core/chat/repository/IChatRepository.js';
3
- import { UserRepository } from '../../../core/user/IUserRepository.js';
4
- import { MessageContext } from '../../../core/IMessageContext.js';
5
- import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
6
- import 'reflect-metadata';
7
- import '../../../injection/index.js';
8
- import '../../../mindset/metadata/MindsetMetadataStore.js';
9
- import { mindsetModule } from '../../../mindset/metadata/modules/@mindsetModule.js';
10
- import '../../../mindset/MindsetOperator.js';
11
- import { EmailService } from '../../service/EmailService.js';
12
- import { OtpService } from '../../service/OtpService.js';
13
- import { SendOneTimePasswordRequest } from './requests/SendOneTimePasswordRequest.js';
14
- import { ValidateOneTimePasswordRequest } from './requests/ValidateOneTimePasswordRequest.js';
15
-
16
- let AuthenticationModule = class AuthenticationModule {
17
- userRepository;
18
- emailService;
19
- otpService;
20
- context;
21
- constructor(userRepository, emailService, otpService, context) {
22
- this.userRepository = userRepository;
23
- this.emailService = emailService;
24
- this.otpService = otpService;
25
- this.context = context;
26
- }
27
- async sendOneTimePassword(request) {
28
- const user = await this.userRepository.findByConnection({
29
- channelName: 'EmailChannel',
30
- id: request.toEmail,
31
- });
32
- if (!user)
33
- return 'success';
34
- const otp = await this.otpService.generate();
35
- const html = await this.generateOtpEmailHtml(otp, user);
36
- const subject = await this.generateOtpEmailSubject();
37
- await this.emailService.sendEmail({
38
- from: request.fromEmail,
39
- to: request.toEmail,
40
- subject,
41
- html,
42
- });
43
- user.setValue('OTP', otp);
44
- await this.userRepository.update(user);
45
- return 'success';
46
- }
47
- async validateOneTimePassword(request) {
48
- const user = await this.userRepository.findByConnection({
49
- channelName: 'EmailChannel',
50
- id: request.userEmail,
51
- });
52
- if (!user) {
53
- throw new Error('Invalid OTP');
54
- }
55
- const otp = user.getValue('OTP');
56
- if (otp !== request.otp) {
57
- throw new Error('Invalid OTP');
58
- }
59
- user.addConnection(this.context.message.userConnection);
60
- await this.userRepository.update(user);
61
- return 'success';
62
- }
63
- async generateOtpEmailHtml(otp, user) {
64
- return `<p>Your OTP Code is ${otp}</p>`;
65
- }
66
- async generateOtpEmailSubject() {
67
- return 'OTP Code';
68
- }
69
- };
70
- __decorate([
71
- mindsetFunction({
72
- description: 'Send an One Time Password to the user when want authenticate',
73
- }),
74
- __metadata("design:type", Function),
75
- __metadata("design:paramtypes", [SendOneTimePasswordRequest]),
76
- __metadata("design:returntype", Promise)
77
- ], AuthenticationModule.prototype, "sendOneTimePassword", null);
78
- __decorate([
79
- mindsetFunction({
80
- description: 'Send an One Time Password to the user when want authenticate',
81
- }),
82
- __metadata("design:type", Function),
83
- __metadata("design:paramtypes", [ValidateOneTimePasswordRequest]),
84
- __metadata("design:returntype", Promise)
85
- ], AuthenticationModule.prototype, "validateOneTimePassword", null);
86
- AuthenticationModule = __decorate([
87
- mindsetModule({
88
- description: 'Provide authentication methods',
89
- language: 'english',
90
- }),
91
- __metadata("design:paramtypes", [UserRepository,
92
- EmailService,
93
- OtpService,
94
- MessageContext])
95
- ], AuthenticationModule);
96
-
97
- export { AuthenticationModule };
@@ -1,25 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import 'reflect-metadata';
3
- import '../../../../injection/index.js';
4
- import '../../../../mindset/metadata/MindsetMetadataStore.js';
5
- import { param } from '../../../../mindset/metadata/params/@param.js';
6
- import '../../../../mindset/MindsetOperator.js';
7
-
8
- class SendOneTimePasswordRequest {
9
- fromEmail = '';
10
- toEmail = '';
11
- }
12
- __decorate([
13
- param({
14
- description: 'Sender Email address',
15
- }),
16
- __metadata("design:type", String)
17
- ], SendOneTimePasswordRequest.prototype, "fromEmail", void 0);
18
- __decorate([
19
- param({
20
- description: 'Recipient Email Address, to send one time password',
21
- }),
22
- __metadata("design:type", String)
23
- ], SendOneTimePasswordRequest.prototype, "toEmail", void 0);
24
-
25
- export { SendOneTimePasswordRequest };
@@ -1,25 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import 'reflect-metadata';
3
- import '../../../../injection/index.js';
4
- import '../../../../mindset/metadata/MindsetMetadataStore.js';
5
- import { param } from '../../../../mindset/metadata/params/@param.js';
6
- import '../../../../mindset/MindsetOperator.js';
7
-
8
- class ValidateOneTimePasswordRequest {
9
- userEmail = '';
10
- otp = '';
11
- }
12
- __decorate([
13
- param({
14
- description: 'User Email',
15
- }),
16
- __metadata("design:type", String)
17
- ], ValidateOneTimePasswordRequest.prototype, "userEmail", void 0);
18
- __decorate([
19
- param({
20
- description: 'Otp provided by the User',
21
- }),
22
- __metadata("design:type", String)
23
- ], ValidateOneTimePasswordRequest.prototype, "otp", void 0);
24
-
25
- export { ValidateOneTimePasswordRequest };
@@ -1,56 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../../core/chat/repository/IChatRepository.js';
3
- import { User } from '../../../core/user/User.js';
4
- import { UserRepository } from '../../../core/user/IUserRepository.js';
5
- import { MessageContext } from '../../../core/IMessageContext.js';
6
- import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
7
- import 'reflect-metadata';
8
- import '../../../injection/index.js';
9
- import '../../../mindset/metadata/MindsetMetadataStore.js';
10
- import { mindsetModule } from '../../../mindset/metadata/modules/@mindsetModule.js';
11
- import '../../../mindset/MindsetOperator.js';
12
- import { RegisterUserWithEmailRequest } from './requests/RegisterUserWithEmailRequest.js';
13
-
14
- let RegisterUserModule = class RegisterUserModule {
15
- userRepository;
16
- context;
17
- constructor(userRepository, context) {
18
- this.userRepository = userRepository;
19
- this.context = context;
20
- }
21
- async registerUserWithEmail(request) {
22
- if (this.context.user) {
23
- throw new Error('The User is already authenticated');
24
- }
25
- const user = new User({
26
- shortName: request.shortName,
27
- connections: [
28
- {
29
- channelName: 'EmailChannel',
30
- id: request.email,
31
- },
32
- ],
33
- keyValueData: {},
34
- });
35
- await this.userRepository.create(user);
36
- return 'success';
37
- }
38
- };
39
- __decorate([
40
- mindsetFunction({
41
- description: 'Register a new user using email',
42
- }),
43
- __metadata("design:type", Function),
44
- __metadata("design:paramtypes", [RegisterUserWithEmailRequest]),
45
- __metadata("design:returntype", Promise)
46
- ], RegisterUserModule.prototype, "registerUserWithEmail", null);
47
- RegisterUserModule = __decorate([
48
- mindsetModule({
49
- description: 'Provide functions to register an user',
50
- language: 'english',
51
- }),
52
- __metadata("design:paramtypes", [UserRepository,
53
- MessageContext])
54
- ], RegisterUserModule);
55
-
56
- export { RegisterUserModule };
@@ -1,25 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import 'reflect-metadata';
3
- import '../../../../injection/index.js';
4
- import '../../../../mindset/metadata/MindsetMetadataStore.js';
5
- import { param } from '../../../../mindset/metadata/params/@param.js';
6
- import '../../../../mindset/MindsetOperator.js';
7
-
8
- class RegisterUserWithEmailRequest {
9
- email = '';
10
- shortName = '';
11
- }
12
- __decorate([
13
- param({
14
- description: 'Email of the User',
15
- }),
16
- __metadata("design:type", String)
17
- ], RegisterUserWithEmailRequest.prototype, "email", void 0);
18
- __decorate([
19
- param({
20
- description: 'ShortName for the new User',
21
- }),
22
- __metadata("design:type", String)
23
- ], RegisterUserWithEmailRequest.prototype, "shortName", void 0);
24
-
25
- export { RegisterUserWithEmailRequest };
@@ -1,33 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../../../core/chat/repository/IChatRepository.js';
3
- import { User } from '../../../../core/user/User.js';
4
- import '../../../../core/user/IUserRepository.js';
5
- import { singleton } from '../../../../injection/index.js';
6
- import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
7
- import { Pool } from 'pg';
8
-
9
- let PgUserRepository = class PgUserRepository extends PgCrudRepository {
10
- constructor(pool) {
11
- super(pool, {
12
- table: 'user',
13
- schema: 'wabot',
14
- constructor: User,
15
- });
16
- }
17
- async findByConnection(query) {
18
- const sql = `
19
- SELECT ${this.columns}
20
- FROM ${this.table}
21
- WHERE data->'connections' @> $1::jsonb
22
- LIMIT 1
23
- `;
24
- const items = await this.query(sql, [JSON.stringify([query])]);
25
- return items.at(0) ?? null;
26
- }
27
- };
28
- PgUserRepository = __decorate([
29
- singleton(),
30
- __metadata("design:paramtypes", [Pool])
31
- ], PgUserRepository);
32
-
33
- export { PgUserRepository };
@@ -1,27 +0,0 @@
1
- import { __decorate } from 'tslib';
2
- import { v4 } from 'uuid';
3
- import { singleton } from '../../../../injection/index.js';
4
-
5
- let RamUserRepository = class RamUserRepository {
6
- items = [];
7
- async create(chat) {
8
- if (chat.wasCreated()) {
9
- throw new Error('User already created');
10
- }
11
- chat['data'].id = v4();
12
- chat['data'].createdAt = new Date().getTime();
13
- chat.validate();
14
- this.items.push(chat);
15
- }
16
- async findByConnection(query) {
17
- return this.items.find((item) => item.hasConnection(query)) ?? null;
18
- }
19
- async update(chat) {
20
- // TODO
21
- }
22
- };
23
- RamUserRepository = __decorate([
24
- singleton()
25
- ], RamUserRepository);
26
-
27
- export { RamUserRepository };
@@ -1,13 +0,0 @@
1
- import { __decorate } from 'tslib';
2
- import { injectable } from '../../injection/index.js';
3
-
4
- let EmailService = class EmailService {
5
- async sendEmail(request) {
6
- throw new Error('Not implemented');
7
- }
8
- };
9
- EmailService = __decorate([
10
- injectable()
11
- ], EmailService);
12
-
13
- export { EmailService };