@flowerforce/flowerbase 1.0.1-beta.10

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 (292) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/LICENSE +3 -0
  3. package/README.md +18 -0
  4. package/dist/auth/controller.d.ts +8 -0
  5. package/dist/auth/controller.d.ts.map +1 -0
  6. package/dist/auth/controller.js +76 -0
  7. package/dist/auth/dtos.d.ts +6 -0
  8. package/dist/auth/dtos.d.ts.map +1 -0
  9. package/dist/auth/dtos.js +2 -0
  10. package/dist/auth/plugins/jwt.d.ts +14 -0
  11. package/dist/auth/plugins/jwt.d.ts.map +1 -0
  12. package/dist/auth/plugins/jwt.js +68 -0
  13. package/dist/auth/providers/local-userpass/controller.d.ts +8 -0
  14. package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -0
  15. package/dist/auth/providers/local-userpass/controller.js +184 -0
  16. package/dist/auth/providers/local-userpass/dtos.d.ts +35 -0
  17. package/dist/auth/providers/local-userpass/dtos.d.ts.map +1 -0
  18. package/dist/auth/providers/local-userpass/dtos.js +2 -0
  19. package/dist/auth/utils.d.ts +126 -0
  20. package/dist/auth/utils.d.ts.map +1 -0
  21. package/dist/auth/utils.js +125 -0
  22. package/dist/constants.d.ts +20 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/constants.js +36 -0
  25. package/dist/features/endpoints/index.d.ts +10 -0
  26. package/dist/features/endpoints/index.d.ts.map +1 -0
  27. package/dist/features/endpoints/index.js +31 -0
  28. package/dist/features/endpoints/interface.d.ts +27 -0
  29. package/dist/features/endpoints/interface.d.ts.map +1 -0
  30. package/dist/features/endpoints/interface.js +2 -0
  31. package/dist/features/endpoints/utils.d.ts +31 -0
  32. package/dist/features/endpoints/utils.d.ts.map +1 -0
  33. package/dist/features/endpoints/utils.js +88 -0
  34. package/dist/features/functions/controller.d.ts +9 -0
  35. package/dist/features/functions/controller.d.ts.map +1 -0
  36. package/dist/features/functions/controller.js +88 -0
  37. package/dist/features/functions/dtos.d.ts +34 -0
  38. package/dist/features/functions/dtos.d.ts.map +1 -0
  39. package/dist/features/functions/dtos.js +2 -0
  40. package/dist/features/functions/index.d.ts +9 -0
  41. package/dist/features/functions/index.d.ts.map +1 -0
  42. package/dist/features/functions/index.js +28 -0
  43. package/dist/features/functions/interface.d.ts +32 -0
  44. package/dist/features/functions/interface.d.ts.map +1 -0
  45. package/dist/features/functions/interface.js +2 -0
  46. package/dist/features/functions/utils.d.ts +23 -0
  47. package/dist/features/functions/utils.d.ts.map +1 -0
  48. package/dist/features/functions/utils.js +75 -0
  49. package/dist/features/rules/index.d.ts +1 -0
  50. package/dist/features/rules/index.d.ts.map +1 -0
  51. package/dist/features/rules/index.js +1 -0
  52. package/dist/features/rules/interface.d.ts +22 -0
  53. package/dist/features/rules/interface.d.ts.map +1 -0
  54. package/dist/features/rules/interface.js +2 -0
  55. package/dist/features/rules/utils.d.ts +3 -0
  56. package/dist/features/rules/utils.d.ts.map +1 -0
  57. package/dist/features/rules/utils.js +31 -0
  58. package/dist/features/triggers/dtos.d.ts +9 -0
  59. package/dist/features/triggers/dtos.d.ts.map +1 -0
  60. package/dist/features/triggers/dtos.js +2 -0
  61. package/dist/features/triggers/index.d.ts +10 -0
  62. package/dist/features/triggers/index.d.ts.map +1 -0
  63. package/dist/features/triggers/index.js +59 -0
  64. package/dist/features/triggers/interface.d.ts +44 -0
  65. package/dist/features/triggers/interface.d.ts.map +1 -0
  66. package/dist/features/triggers/interface.js +2 -0
  67. package/dist/features/triggers/utils.d.ts +16 -0
  68. package/dist/features/triggers/utils.d.ts.map +1 -0
  69. package/dist/features/triggers/utils.js +153 -0
  70. package/dist/index.d.ts +19 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +100 -0
  73. package/dist/model.d.ts +2 -0
  74. package/dist/model.d.ts.map +1 -0
  75. package/dist/model.js +2 -0
  76. package/dist/services/api/index.d.ts +36 -0
  77. package/dist/services/api/index.d.ts.map +1 -0
  78. package/dist/services/api/index.js +36 -0
  79. package/dist/services/api/model.d.ts +33 -0
  80. package/dist/services/api/model.d.ts.map +1 -0
  81. package/dist/services/api/model.js +2 -0
  82. package/dist/services/api/utils.d.ts +16 -0
  83. package/dist/services/api/utils.d.ts.map +1 -0
  84. package/dist/services/api/utils.js +45 -0
  85. package/dist/services/aws/index.d.ts +13 -0
  86. package/dist/services/aws/index.d.ts.map +1 -0
  87. package/dist/services/aws/index.js +50 -0
  88. package/dist/services/index.d.ts +41 -0
  89. package/dist/services/index.d.ts.map +1 -0
  90. package/dist/services/index.js +14 -0
  91. package/dist/services/interface.d.ts +3 -0
  92. package/dist/services/interface.d.ts.map +1 -0
  93. package/dist/services/interface.js +2 -0
  94. package/dist/services/mongodb-atlas/index.d.ts +4 -0
  95. package/dist/services/mongodb-atlas/index.d.ts.map +1 -0
  96. package/dist/services/mongodb-atlas/index.js +483 -0
  97. package/dist/services/mongodb-atlas/model.d.ts +39 -0
  98. package/dist/services/mongodb-atlas/model.d.ts.map +1 -0
  99. package/dist/services/mongodb-atlas/model.js +2 -0
  100. package/dist/services/mongodb-atlas/utils.d.ts +8 -0
  101. package/dist/services/mongodb-atlas/utils.d.ts.map +1 -0
  102. package/dist/services/mongodb-atlas/utils.js +33 -0
  103. package/dist/state.d.ts +6 -0
  104. package/dist/state.d.ts.map +1 -0
  105. package/dist/state.js +18 -0
  106. package/dist/utils/context/helpers.d.ts +74 -0
  107. package/dist/utils/context/helpers.d.ts.map +1 -0
  108. package/dist/utils/context/helpers.js +60 -0
  109. package/dist/utils/context/index.d.ts +14 -0
  110. package/dist/utils/context/index.d.ts.map +1 -0
  111. package/dist/utils/context/index.js +65 -0
  112. package/dist/utils/context/interface.d.ts +18 -0
  113. package/dist/utils/context/interface.d.ts.map +1 -0
  114. package/dist/utils/context/interface.js +2 -0
  115. package/dist/utils/crypto/index.d.ts +19 -0
  116. package/dist/utils/crypto/index.d.ts.map +1 -0
  117. package/dist/utils/crypto/index.js +50 -0
  118. package/dist/utils/helpers/someAsync.d.ts +12 -0
  119. package/dist/utils/helpers/someAsync.d.ts.map +1 -0
  120. package/dist/utils/helpers/someAsync.js +56 -0
  121. package/dist/utils/index.d.ts +3 -0
  122. package/dist/utils/index.d.ts.map +1 -0
  123. package/dist/utils/index.js +11 -0
  124. package/dist/utils/initializer/exposeRoutes.d.ts +8 -0
  125. package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -0
  126. package/dist/utils/initializer/exposeRoutes.js +41 -0
  127. package/dist/utils/initializer/registerPlugins.d.ts +19 -0
  128. package/dist/utils/initializer/registerPlugins.d.ts.map +1 -0
  129. package/dist/utils/initializer/registerPlugins.js +96 -0
  130. package/dist/utils/roles/helpers.d.ts +4 -0
  131. package/dist/utils/roles/helpers.d.ts.map +1 -0
  132. package/dist/utils/roles/helpers.js +47 -0
  133. package/dist/utils/roles/interface.d.ts +33 -0
  134. package/dist/utils/roles/interface.d.ts.map +1 -0
  135. package/dist/utils/roles/interface.js +2 -0
  136. package/dist/utils/roles/machines/commonValidators.d.ts +6 -0
  137. package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -0
  138. package/dist/utils/roles/machines/commonValidators.js +34 -0
  139. package/dist/utils/roles/machines/index.d.ts +14 -0
  140. package/dist/utils/roles/machines/index.d.ts.map +1 -0
  141. package/dist/utils/roles/machines/index.js +27 -0
  142. package/dist/utils/roles/machines/interface.d.ts +46 -0
  143. package/dist/utils/roles/machines/interface.d.ts.map +1 -0
  144. package/dist/utils/roles/machines/interface.js +2 -0
  145. package/dist/utils/roles/machines/machine.d.ts +15 -0
  146. package/dist/utils/roles/machines/machine.d.ts.map +1 -0
  147. package/dist/utils/roles/machines/machine.js +97 -0
  148. package/dist/utils/roles/machines/read/A/index.d.ts +3 -0
  149. package/dist/utils/roles/machines/read/A/index.d.ts.map +1 -0
  150. package/dist/utils/roles/machines/read/A/index.js +27 -0
  151. package/dist/utils/roles/machines/read/B/index.d.ts +3 -0
  152. package/dist/utils/roles/machines/read/B/index.d.ts.map +1 -0
  153. package/dist/utils/roles/machines/read/B/index.js +36 -0
  154. package/dist/utils/roles/machines/read/C/index.d.ts +3 -0
  155. package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -0
  156. package/dist/utils/roles/machines/read/C/index.js +38 -0
  157. package/dist/utils/roles/machines/read/D/index.d.ts +3 -0
  158. package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -0
  159. package/dist/utils/roles/machines/read/D/index.js +26 -0
  160. package/dist/utils/roles/machines/read/D/validators.d.ts +4 -0
  161. package/dist/utils/roles/machines/read/D/validators.d.ts.map +1 -0
  162. package/dist/utils/roles/machines/read/D/validators.js +24 -0
  163. package/dist/utils/roles/machines/read/index.d.ts +2 -0
  164. package/dist/utils/roles/machines/read/index.d.ts.map +1 -0
  165. package/dist/utils/roles/machines/read/index.js +8 -0
  166. package/dist/utils/roles/machines/utils.d.ts +37 -0
  167. package/dist/utils/roles/machines/utils.d.ts.map +1 -0
  168. package/dist/utils/roles/machines/utils.js +54 -0
  169. package/dist/utils/roles/machines/write/A/index.d.ts +3 -0
  170. package/dist/utils/roles/machines/write/A/index.d.ts.map +1 -0
  171. package/dist/utils/roles/machines/write/A/index.js +29 -0
  172. package/dist/utils/roles/machines/write/B/index.d.ts +3 -0
  173. package/dist/utils/roles/machines/write/B/index.d.ts.map +1 -0
  174. package/dist/utils/roles/machines/write/B/index.js +47 -0
  175. package/dist/utils/roles/machines/write/C/index.d.ts +3 -0
  176. package/dist/utils/roles/machines/write/C/index.d.ts.map +1 -0
  177. package/dist/utils/roles/machines/write/C/index.js +26 -0
  178. package/dist/utils/roles/machines/write/C/validators.d.ts +4 -0
  179. package/dist/utils/roles/machines/write/C/validators.d.ts.map +1 -0
  180. package/dist/utils/roles/machines/write/C/validators.js +24 -0
  181. package/dist/utils/roles/machines/write/index.d.ts +2 -0
  182. package/dist/utils/roles/machines/write/index.d.ts.map +1 -0
  183. package/dist/utils/roles/machines/write/index.js +7 -0
  184. package/dist/utils/rules-matcher/interface.d.ts +338 -0
  185. package/dist/utils/rules-matcher/interface.d.ts.map +1 -0
  186. package/dist/utils/rules-matcher/interface.js +26 -0
  187. package/dist/utils/rules-matcher/utils.d.ts +11 -0
  188. package/dist/utils/rules-matcher/utils.d.ts.map +1 -0
  189. package/dist/utils/rules-matcher/utils.js +214 -0
  190. package/dist/utils/rules.d.ts +2 -0
  191. package/dist/utils/rules.d.ts.map +1 -0
  192. package/dist/utils/rules.js +22 -0
  193. package/jest.config.ts +24 -0
  194. package/package.json +62 -0
  195. package/project.json +10 -0
  196. package/rollup.config.js +17 -0
  197. package/src/auth/controller.ts +78 -0
  198. package/src/auth/dtos.ts +6 -0
  199. package/src/auth/plugins/jwt.ts +68 -0
  200. package/src/auth/providers/local-userpass/controller.ts +226 -0
  201. package/src/auth/providers/local-userpass/dtos.ts +40 -0
  202. package/src/auth/utils.ts +168 -0
  203. package/src/babel.config.json +3 -0
  204. package/src/constants.ts +24 -0
  205. package/src/fastify.d.ts +28 -0
  206. package/src/features/endpoints/index.ts +27 -0
  207. package/src/features/endpoints/interface.ts +29 -0
  208. package/src/features/endpoints/utils.ts +74 -0
  209. package/src/features/functions/controller.ts +102 -0
  210. package/src/features/functions/dtos.ts +41 -0
  211. package/src/features/functions/index.ts +21 -0
  212. package/src/features/functions/interface.ts +38 -0
  213. package/src/features/functions/utils.ts +82 -0
  214. package/src/features/rules/index.tsx +0 -0
  215. package/src/features/rules/interface.ts +24 -0
  216. package/src/features/rules/utils.ts +20 -0
  217. package/src/features/triggers/dtos.ts +9 -0
  218. package/src/features/triggers/index.ts +36 -0
  219. package/src/features/triggers/interface.ts +44 -0
  220. package/src/features/triggers/utils.ts +157 -0
  221. package/src/global.d.ts +0 -0
  222. package/src/index.ts +90 -0
  223. package/src/model.ts +1 -0
  224. package/src/services/api/index.ts +50 -0
  225. package/src/services/api/model.ts +38 -0
  226. package/src/services/api/utils.ts +39 -0
  227. package/src/services/aws/index.ts +48 -0
  228. package/src/services/index.ts +9 -0
  229. package/src/services/interface.ts +3 -0
  230. package/src/services/mongodb-atlas/index.ts +569 -0
  231. package/src/services/mongodb-atlas/model.ts +67 -0
  232. package/src/services/mongodb-atlas/utils.ts +44 -0
  233. package/src/state.ts +24 -0
  234. package/src/utils/__tests__/STEP_A_STATES.test.ts +54 -0
  235. package/src/utils/__tests__/STEP_B_STATES.test.ts +113 -0
  236. package/src/utils/__tests__/STEP_C_STATES.test.ts +87 -0
  237. package/src/utils/__tests__/STEP_D_STATES.test.ts +93 -0
  238. package/src/utils/__tests__/checkAdditionalFieldsFn.test.ts +45 -0
  239. package/src/utils/__tests__/checkApplyWhen.test.ts +49 -0
  240. package/src/utils/__tests__/checkFieldsPropertyExists.test.ts +47 -0
  241. package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +190 -0
  242. package/src/utils/__tests__/comparePassword.test.ts +38 -0
  243. package/src/utils/__tests__/evaluateDocumentsFiltersReadFn.test.ts +57 -0
  244. package/src/utils/__tests__/evaluateDocumentsFiltersWriteFn.test.ts +57 -0
  245. package/src/utils/__tests__/evaluateTopLevelReadFn.test.ts +58 -0
  246. package/src/utils/__tests__/evaluateTopLevelWriteFn.test.ts +66 -0
  247. package/src/utils/__tests__/exposeRoutes.test.ts +65 -0
  248. package/src/utils/__tests__/generateContextData.test.ts +75 -0
  249. package/src/utils/__tests__/getDefaultRule.test.ts +29 -0
  250. package/src/utils/__tests__/getKey.test.ts +12 -0
  251. package/src/utils/__tests__/getKeys.test.ts +11 -0
  252. package/src/utils/__tests__/getWinningRole.test.ts +66 -0
  253. package/src/utils/__tests__/hashPassword.test.ts +28 -0
  254. package/src/utils/__tests__/isEmpty.test.ts +17 -0
  255. package/src/utils/__tests__/logMachineInfo.test.ts +15 -0
  256. package/src/utils/__tests__/operators.test.ts +99 -0
  257. package/src/utils/__tests__/readFileContent.test.ts +35 -0
  258. package/src/utils/__tests__/registerPlugins.test.ts +59 -0
  259. package/src/utils/__tests__/rule.test.ts +51 -0
  260. package/src/utils/__tests__/rulesMatcherInterfaces.test.ts +57 -0
  261. package/src/utils/__tests__/rulesMatcherUtils.test.ts +56 -0
  262. package/src/utils/__tests__/someAsync.test.ts +55 -0
  263. package/src/utils/context/helpers.ts +71 -0
  264. package/src/utils/context/index.ts +74 -0
  265. package/src/utils/context/interface.ts +19 -0
  266. package/src/utils/crypto/index.ts +36 -0
  267. package/src/utils/helpers/someAsync.ts +24 -0
  268. package/src/utils/index.ts +5 -0
  269. package/src/utils/initializer/exposeRoutes.ts +26 -0
  270. package/src/utils/initializer/registerPlugins.ts +111 -0
  271. package/src/utils/roles/helpers.ts +47 -0
  272. package/src/utils/roles/interface.ts +42 -0
  273. package/src/utils/roles/machines/commonValidators.ts +24 -0
  274. package/src/utils/roles/machines/index.ts +20 -0
  275. package/src/utils/roles/machines/interface.ts +46 -0
  276. package/src/utils/roles/machines/machine.ts +85 -0
  277. package/src/utils/roles/machines/read/A/index.ts +19 -0
  278. package/src/utils/roles/machines/read/B/index.ts +31 -0
  279. package/src/utils/roles/machines/read/C/index.ts +30 -0
  280. package/src/utils/roles/machines/read/D/index.ts +20 -0
  281. package/src/utils/roles/machines/read/D/validators.ts +24 -0
  282. package/src/utils/roles/machines/read/index.ts +6 -0
  283. package/src/utils/roles/machines/utils.ts +54 -0
  284. package/src/utils/roles/machines/write/A/index.ts +25 -0
  285. package/src/utils/roles/machines/write/B/index.ts +43 -0
  286. package/src/utils/roles/machines/write/C/index.ts +20 -0
  287. package/src/utils/roles/machines/write/C/validators.ts +24 -0
  288. package/src/utils/roles/machines/write/index.ts +5 -0
  289. package/src/utils/rules-matcher/interface.ts +365 -0
  290. package/src/utils/rules-matcher/utils.ts +281 -0
  291. package/src/utils/rules.ts +19 -0
  292. package/tsconfig.json +28 -0
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getMailConfig = exports.loadCustomUserData = exports.loadAuthConfig = exports.PROVIDER_TYPE = exports.AUTH_ERRORS = exports.AUTH_ENDPOINTS = exports.REGISTRATION_SCHEMA = exports.CONFIRM_RESET_SCHEMA = exports.RESET_SCHEMA = exports.LOGIN_SCHEMA = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ exports.LOGIN_SCHEMA = {
10
+ body: {
11
+ type: 'object',
12
+ properties: {
13
+ username: { type: 'string' },
14
+ password: { type: 'string' }
15
+ },
16
+ required: ['username', 'password']
17
+ }
18
+ };
19
+ exports.RESET_SCHEMA = {
20
+ body: {
21
+ type: 'object',
22
+ properties: {
23
+ email: { type: 'string' },
24
+ password: { type: 'string' }
25
+ },
26
+ required: ['email', 'password']
27
+ }
28
+ };
29
+ exports.CONFIRM_RESET_SCHEMA = {
30
+ body: {
31
+ type: 'object',
32
+ properties: {
33
+ password: { type: 'string' },
34
+ token: { type: 'string' },
35
+ tokenId: { type: 'string' }
36
+ },
37
+ required: ['password', 'token', 'tokenId']
38
+ }
39
+ };
40
+ exports.REGISTRATION_SCHEMA = {
41
+ body: {
42
+ type: 'object',
43
+ properties: {
44
+ email: { type: 'string' },
45
+ password: { type: 'string' }
46
+ },
47
+ required: ['email', 'password']
48
+ }
49
+ };
50
+ var AUTH_ENDPOINTS;
51
+ (function (AUTH_ENDPOINTS) {
52
+ AUTH_ENDPOINTS["LOGIN"] = "/login";
53
+ AUTH_ENDPOINTS["REGISTRATION"] = "/register";
54
+ AUTH_ENDPOINTS["PROFILE"] = "/profile";
55
+ AUTH_ENDPOINTS["SESSION"] = "/session";
56
+ AUTH_ENDPOINTS["RESET"] = "/reset/call";
57
+ AUTH_ENDPOINTS["CONFIRM_RESET"] = "/reset";
58
+ })(AUTH_ENDPOINTS || (exports.AUTH_ENDPOINTS = AUTH_ENDPOINTS = {}));
59
+ var AUTH_ERRORS;
60
+ (function (AUTH_ERRORS) {
61
+ AUTH_ERRORS["INVALID_CREDENTIALS"] = "Invalid credentials";
62
+ AUTH_ERRORS["INVALID_TOKEN"] = "Invalid refresh token provided";
63
+ AUTH_ERRORS["INVALID_RESET_PARAMS"] = "Invalid token or tokenId provided";
64
+ })(AUTH_ERRORS || (exports.AUTH_ERRORS = AUTH_ERRORS = {}));
65
+ exports.PROVIDER_TYPE = 'local-userpass';
66
+ /**
67
+ * > Loads the auth config json file
68
+ * @testable
69
+ */
70
+ const loadAuthConfig = () => {
71
+ const authPath = path_1.default.join(require.main.path, 'auth/providers.json');
72
+ return JSON.parse(fs_1.default.readFileSync(authPath, 'utf-8'));
73
+ };
74
+ exports.loadAuthConfig = loadAuthConfig;
75
+ /**
76
+ * > Loads the custom user data config json file
77
+ * @testable
78
+ */
79
+ const loadCustomUserData = () => {
80
+ const userDataPath = path_1.default.join(require.main.path, 'auth/custom_user_data.json');
81
+ return JSON.parse(fs_1.default.readFileSync(userDataPath, 'utf-8'));
82
+ };
83
+ exports.loadCustomUserData = loadCustomUserData;
84
+ const getMailConfig = (resetPasswordConfig, token, tokenId) => {
85
+ var _a, _b, _c;
86
+ const { mailConfig, resetPasswordUrl } = resetPasswordConfig;
87
+ const ENV_PREFIX = "ENV";
88
+ const { from, subject, mailToken } = mailConfig;
89
+ const [fromPrefix, fromPath] = from.split(".");
90
+ const currentSender = (_a = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from)) !== null && _a !== void 0 ? _a : "";
91
+ const [subjectPrefix, subjectPath] = subject.split(".");
92
+ const currentSubject = (_b = (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject)) !== null && _b !== void 0 ? _b : "";
93
+ const [mailTokenPrefix, mailTokenPath] = mailToken.split(".");
94
+ const currentMailToken = (_c = (mailTokenPrefix === "ENV" ? process.env[mailTokenPath] : mailToken)) !== null && _c !== void 0 ? _c : "";
95
+ const link = `${resetPasswordUrl}/${token}/${tokenId}`;
96
+ const body = `<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; padding: 20px;">
97
+ <table width="100%" cellspacing="0" cellpadding="0">
98
+ <tr>
99
+ <td align="center">
100
+ <table width="600" cellspacing="0" cellpadding="0" style="background: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);">
101
+ <tr>
102
+ <td align="center">
103
+ <h2>Password Reset Request</h2>
104
+ <p>If you requested a password reset, click the button below to reset your password.</p>
105
+ <p>If you did not request this, please ignore this email.</p>
106
+ <p>
107
+ <a href="${link}" style="display: inline-block; padding: 12px 20px; font-size: 16px; color: #ffffff; background: #007bff; text-decoration: none; border-radius: 5px;">Reset Password</a>
108
+ </p>
109
+ <p style="margin-top: 20px; font-size: 12px; color: #777;">If the button does not work, copy and paste the following link into your browser:</p>
110
+ <p style="font-size: 12px; color: #777;">${link}</p>
111
+ </td>
112
+ </tr>
113
+ </table>
114
+ </td>
115
+ </tr>
116
+ </table>
117
+ </body>`;
118
+ return {
119
+ from: currentSender !== null && currentSender !== void 0 ? currentSender : "",
120
+ subject: currentSubject,
121
+ mailToken: currentMailToken,
122
+ body
123
+ };
124
+ };
125
+ exports.getMailConfig = getMailConfig;
@@ -0,0 +1,20 @@
1
+ export declare const DEFAULT_CONFIG: {
2
+ PORT: number;
3
+ MONGODB_URL: string;
4
+ JWT_SECRET: string;
5
+ API_VERSION: string;
6
+ HTTPS_SCHEMA: string;
7
+ HOST: string;
8
+ ENABLE_LOGGER: string | undefined;
9
+ };
10
+ export declare const API_VERSION: string;
11
+ export declare const HTTPS_SCHEMA: string;
12
+ export declare const DB_NAME: string;
13
+ export declare const AUTH_CONFIG: {
14
+ authCollection: string;
15
+ userCollection: string;
16
+ resetPasswordCollection: string;
17
+ resetPasswordConfig: import("./auth/utils").Config;
18
+ user_id_field: string;
19
+ };
20
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;CAMvB,CAAA"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
15
+ const utils_1 = require("./auth/utils");
16
+ const { database_name, collection_name = 'users', user_id_field = "id" } = (0, utils_1.loadCustomUserData)();
17
+ const _a = (0, utils_1.loadAuthConfig)(), { auth_collection = 'auth_users' } = _a, configuration = __rest(_a, ["auth_collection"]);
18
+ exports.DEFAULT_CONFIG = {
19
+ PORT: Number(process.env.PORT) || 3000,
20
+ MONGODB_URL: process.env.MONGODB_URL || '',
21
+ JWT_SECRET: process.env.JWT_SECRET || '',
22
+ API_VERSION: process.env.API_VERSION || "v2.0",
23
+ HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
24
+ HOST: process.env.HOST || '0.0.0.0',
25
+ ENABLE_LOGGER: process.env.ENABLE_LOGGER
26
+ };
27
+ exports.API_VERSION = `/api/client/${exports.DEFAULT_CONFIG.API_VERSION}`;
28
+ exports.HTTPS_SCHEMA = exports.DEFAULT_CONFIG.HTTPS_SCHEMA;
29
+ exports.DB_NAME = database_name;
30
+ exports.AUTH_CONFIG = {
31
+ authCollection: auth_collection,
32
+ userCollection: collection_name,
33
+ resetPasswordCollection: "reset-password-requests",
34
+ resetPasswordConfig: configuration['local-userpass'].config,
35
+ user_id_field
36
+ };
@@ -0,0 +1,10 @@
1
+ import { GenerateEndpointsParams } from './interface';
2
+ /**
3
+ * > Generates all HTTP endpoints
4
+ * @testable
5
+ * @param app -> the fastify instance
6
+ * @param functionsList -> the list of all functions
7
+ * @param endpointsList -> the list of all endpoints
8
+ */
9
+ export declare const generateEndpoints: ({ app, functionsList, endpointsList }: GenerateEndpointsParams) => Promise<void>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAGrD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAU,uCAIrC,uBAAuB,kBAYzB,CAAA"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.generateEndpoints = void 0;
13
+ const utils_1 = require("./utils");
14
+ /**
15
+ * > Generates all HTTP endpoints
16
+ * @testable
17
+ * @param app -> the fastify instance
18
+ * @param functionsList -> the list of all functions
19
+ * @param endpointsList -> the list of all endpoints
20
+ */
21
+ const generateEndpoints = (_a) => __awaiter(void 0, [_a], void 0, function* ({ app, functionsList, endpointsList }) {
22
+ endpointsList.forEach(({ http_method, route, disabled, function_name }) => {
23
+ const currentFunction = functionsList[function_name];
24
+ if (disabled || !currentFunction)
25
+ return;
26
+ const handler = (0, utils_1.generateHandler)({ app, currentFunction, functionsList });
27
+ const currentMethod = (0, utils_1.getMethodsConfig)(app, handler, `/app/:appId/endpoint/${route}`)[http_method];
28
+ currentMethod();
29
+ });
30
+ });
31
+ exports.generateEndpoints = generateEndpoints;
@@ -0,0 +1,27 @@
1
+ import { FastifyInstance } from 'fastify';
2
+ import { Function, Functions } from '../functions/interface';
3
+ export type GenerateEndpointsParams = {
4
+ app: FastifyInstance;
5
+ functionsList: Functions;
6
+ endpointsList: Endpoints;
7
+ };
8
+ export type GenerateHandlerParams = {
9
+ app: FastifyInstance;
10
+ currentFunction: Function;
11
+ functionsList: Functions;
12
+ };
13
+ type HTTP_METHOD<T> = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | T;
14
+ export type Endpoint<T = 'ALL'> = {
15
+ http_method: HTTP_METHOD<T>;
16
+ route: string;
17
+ function_name: string;
18
+ secret_name: string;
19
+ validation_method: string;
20
+ respond_result: boolean;
21
+ fetch_custom_user_data: boolean;
22
+ create_user_on_auth: boolean;
23
+ disabled: boolean;
24
+ };
25
+ export type Endpoints<T = 'ALL'> = Endpoint<T>[];
26
+ export {};
27
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE5D,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,aAAa,EAAE,SAAS,CAAA;IACxB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,eAAe,CAAA;IACpB,eAAe,EAAE,QAAQ,CAAA;IACzB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAED,KAAK,WAAW,CAAC,CAAC,IAAI,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,CAAC,CAAA;AAErE,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,KAAK,IAAI;IAChC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,CAAA;IACzB,cAAc,EAAE,OAAO,CAAA;IACvB,sBAAsB,EAAE,OAAO,CAAA;IAC/B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AACD,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
2
+ import { Endpoints, GenerateHandlerParams } from './interface';
3
+ /**
4
+ * > Loads the endpoint config json file
5
+ * @testable
6
+ */
7
+ export declare const loadEndpoints: (rootDir?: string) => Promise<Endpoints>;
8
+ /**
9
+ * > Creates an object with a config for all HTTP methods
10
+ * @testable
11
+ * @param app -> the fastify instance
12
+ * @param handler -> the handler function for that route
13
+ * @param endpoint -> the current endpoint
14
+ */
15
+ export declare const getMethodsConfig: (app: FastifyInstance, handler: ReturnType<typeof generateHandler>, endpoint: string) => {
16
+ ALL: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
17
+ GET: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
18
+ POST: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
19
+ PUT: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
20
+ PATCH: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
21
+ DELETE: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
22
+ };
23
+ /**
24
+ * > Creates an handler function for a single endpoint
25
+ * @testable
26
+ * @param app -> the fastify instance
27
+ * @param currentFunction -> the name of the function that should be called for that endpoint
28
+ * @param functionsList -> the list of all functions
29
+ */
30
+ export declare const generateHandler: ({ app, currentFunction, functionsList }: GenerateHandlerParams) => (req: FastifyRequest, res: FastifyReply) => Promise<{}>;
31
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKvE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAS9E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,KAAK,eAAe,EACpB,SAAS,UAAU,CAAC,OAAO,eAAe,CAAC,EAC3C,UAAU,MAAM;;;;;;;CAQhB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,yCAI7B,qBAAqB,MACR,KAAK,cAAc,EAAE,KAAK,YAAY,gBAiBrD,CAAA"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateHandler = exports.getMethodsConfig = exports.loadEndpoints = void 0;
27
+ const fs_1 = __importDefault(require("fs"));
28
+ const node_path_1 = __importDefault(require("node:path"));
29
+ const services_1 = require("../../services");
30
+ const context_1 = require("../../utils/context");
31
+ /**
32
+ * > Loads the endpoint config json file
33
+ * @testable
34
+ */
35
+ const loadEndpoints = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (rootDir = process.cwd()) {
36
+ const endpointsDir = 'http_endpoints';
37
+ const endPointsFile = node_path_1.default.join(rootDir, endpointsDir, 'config.json');
38
+ const config = JSON.parse(fs_1.default.readFileSync(endPointsFile, 'utf-8'));
39
+ return config.map((_a) => {
40
+ var { http_method } = _a, endpoint = __rest(_a, ["http_method"]);
41
+ return (Object.assign({ http_method: http_method === '*' ? 'ALL' : http_method }, endpoint));
42
+ });
43
+ });
44
+ exports.loadEndpoints = loadEndpoints;
45
+ /**
46
+ * > Creates an object with a config for all HTTP methods
47
+ * @testable
48
+ * @param app -> the fastify instance
49
+ * @param handler -> the handler function for that route
50
+ * @param endpoint -> the current endpoint
51
+ */
52
+ const getMethodsConfig = (app, handler, endpoint) => ({
53
+ ALL: () => app.all(endpoint, handler),
54
+ GET: () => app.get(endpoint, handler),
55
+ POST: () => app.post(endpoint, handler),
56
+ PUT: () => app.put(endpoint, handler),
57
+ PATCH: () => app.patch(endpoint, handler),
58
+ DELETE: () => app.delete(endpoint, handler)
59
+ });
60
+ exports.getMethodsConfig = getMethodsConfig;
61
+ /**
62
+ * > Creates an handler function for a single endpoint
63
+ * @testable
64
+ * @param app -> the fastify instance
65
+ * @param currentFunction -> the name of the function that should be called for that endpoint
66
+ * @param functionsList -> the list of all functions
67
+ */
68
+ const generateHandler = ({ app, currentFunction, functionsList }) => {
69
+ return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
70
+ try {
71
+ const response = yield (0, context_1.GenerateContext)({
72
+ args: [req],
73
+ app,
74
+ rules: {}, //TODO -> check rules
75
+ user: req.user,
76
+ currentFunction,
77
+ functionsList,
78
+ services: services_1.services
79
+ });
80
+ res.send(response);
81
+ }
82
+ catch (e) {
83
+ console.log(e);
84
+ }
85
+ return {};
86
+ });
87
+ };
88
+ exports.generateHandler = generateHandler;
@@ -0,0 +1,9 @@
1
+ import { FunctionController } from './interface';
2
+ /**
3
+ * > Creates a pre handler for every query
4
+ * @param app -> the fastify instance
5
+ * @param functionsList -> the list of all functions
6
+ * @param rules -> all the rules
7
+ */
8
+ export declare const functionsController: FunctionController;
9
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAqFjC,CAAA"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.functionsController = void 0;
13
+ const bson_1 = require("bson");
14
+ const services_1 = require("../../services");
15
+ const state_1 = require("../../state");
16
+ const context_1 = require("../../utils/context");
17
+ const utils_1 = require("./utils");
18
+ /**
19
+ * > Creates a pre handler for every query
20
+ * @param app -> the fastify instance
21
+ * @param functionsList -> the list of all functions
22
+ * @param rules -> all the rules
23
+ */
24
+ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0, function* (app, { functionsList, rules }) {
25
+ app.addHook('preHandler', app.jwtAuthentication);
26
+ app.post('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
27
+ const { user } = req;
28
+ const { name: method, arguments: args } = req.body;
29
+ if ('service' in req.body) {
30
+ const serviceFn = services_1.services[req.body.service];
31
+ if (!serviceFn) {
32
+ throw new Error(`Service "${req.body.service}" does not exist`);
33
+ }
34
+ const [{ database, collection, query, update, document }] = args;
35
+ const currentMethod = serviceFn(app, { rules, user })
36
+ .db(database)
37
+ .collection(collection)[method];
38
+ const operatorsByType = yield (0, utils_1.executeQuery)({
39
+ currentMethod,
40
+ query,
41
+ update,
42
+ document
43
+ });
44
+ return operatorsByType[method]();
45
+ }
46
+ const currentFunction = functionsList[method];
47
+ if (!currentFunction) {
48
+ throw new Error(`Function "${req.body.name}" does not exist`);
49
+ }
50
+ if (currentFunction.private) {
51
+ throw new Error(`Function "${req.body.name}" is private`);
52
+ }
53
+ const result = yield (0, context_1.GenerateContext)({
54
+ args: req.body.arguments,
55
+ app,
56
+ rules,
57
+ user: Object.assign(Object.assign({}, user), { _id: new bson_1.ObjectId(user.id) }),
58
+ currentFunction,
59
+ functionsList,
60
+ services: services_1.services
61
+ });
62
+ res.type("application/json");
63
+ return JSON.stringify(result);
64
+ }));
65
+ app.get('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
66
+ const { query, user } = req;
67
+ const { baas_request, stitch_request } = query;
68
+ const config = JSON.parse(Buffer.from(baas_request || stitch_request || "", "base64").toString("utf8"));
69
+ const [{ database, collection }] = config.arguments;
70
+ const app = state_1.StateManager.select("app");
71
+ const services = state_1.StateManager.select("services");
72
+ const changeStream = yield services["mongodb-atlas"](app, {
73
+ user,
74
+ rules
75
+ }).db(database).collection(collection).watch([], { fullDocument: "whenAvailable" });
76
+ res.header('Content-Type', 'text/event-stream');
77
+ res.header('Cache-Control', 'no-cache');
78
+ res.header('Connection', 'keep-alive');
79
+ res.raw.flushHeaders();
80
+ changeStream.on('change', (change) => {
81
+ res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
82
+ });
83
+ req.raw.on('close', () => {
84
+ changeStream.close();
85
+ });
86
+ }));
87
+ });
88
+ exports.functionsController = functionsController;
@@ -0,0 +1,34 @@
1
+ import { Document } from "mongodb";
2
+ import { Arguments } from '../../auth/dtos';
3
+ import { GetOperatorsFunction } from '../../services/mongodb-atlas/model';
4
+ type MethodName = Exclude<keyof ReturnType<GetOperatorsFunction>, 'match'>;
5
+ export type FunctionCallDto = {
6
+ name: MethodName;
7
+ arguments: ArgumentsData;
8
+ } | {
9
+ arguments: ArgumentsData;
10
+ name: MethodName;
11
+ service: 'mongodb-atlas';
12
+ };
13
+ export type FunctionCallBase64Dto = {
14
+ baas_request?: string;
15
+ stitch_request?: string;
16
+ };
17
+ type ArgumentsData = Arguments<{
18
+ database: string;
19
+ collection: string;
20
+ query: Parameters<GetOperatorsFunction>;
21
+ update: Document;
22
+ document: Document;
23
+ }>;
24
+ export type Base64Function = {
25
+ name: string;
26
+ arguments: Argument[];
27
+ service: string;
28
+ };
29
+ type Argument = {
30
+ database: string;
31
+ collection: string;
32
+ };
33
+ export {};
34
+ //# sourceMappingURL=dtos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../src/features/functions/dtos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAEzE,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAA;AAE1E,MAAM,MAAM,eAAe,GACvB;IACA,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,aAAa,CAAA;CACzB,GACC;IACA,SAAS,EAAE,aAAa,CAAA;IACxB,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,eAAe,CAAA;CACzB,CAAA;AAEH,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,KAAK,aAAa,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACvC,MAAM,EAAE,QAAQ,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAC,CAAA;AAGF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,QAAQ,GAAG;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { RegisterFunctionsParams } from './interface';
2
+ /**
3
+ * > Registers the functions controller
4
+ * @param app -> the fastify instance
5
+ * @param functionsList -> the list of all functions
6
+ * @param rulesList -> the list of all rules
7
+ */
8
+ export declare const registerFunctions: ({ app, rulesList, functionsList }: RegisterFunctionsParams) => Promise<void>;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/functions/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAU,mCAIrC,uBAAuB,kBAMzB,CAAA"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.registerFunctions = void 0;
13
+ const constants_1 = require("../../constants");
14
+ const controller_1 = require("./controller");
15
+ /**
16
+ * > Registers the functions controller
17
+ * @param app -> the fastify instance
18
+ * @param functionsList -> the list of all functions
19
+ * @param rulesList -> the list of all rules
20
+ */
21
+ const registerFunctions = (_a) => __awaiter(void 0, [_a], void 0, function* ({ app, rulesList, functionsList }) {
22
+ yield app.register(controller_1.functionsController, {
23
+ functionsList,
24
+ rules: rulesList,
25
+ prefix: `${constants_1.API_VERSION}/app/:appId/functions`
26
+ });
27
+ });
28
+ exports.registerFunctions = registerFunctions;
@@ -0,0 +1,32 @@
1
+ import { FastifyInstance } from 'fastify';
2
+ import { Document } from "mongodb";
3
+ import { GetOperatorsFunction } from '../../services/mongodb-atlas/model';
4
+ import { Rules } from '../rules/interface';
5
+ export interface FunctionConfig {
6
+ name: string;
7
+ private?: boolean;
8
+ run_as_system?: boolean;
9
+ disable_arg_logs?: boolean;
10
+ }
11
+ export type Function = Omit<FunctionConfig, 'name'> & {
12
+ code: string;
13
+ };
14
+ export type Functions = Record<string, Function>;
15
+ export type RegisterFunctionsParams = {
16
+ app: FastifyInstance;
17
+ functionsList: Functions;
18
+ rulesList: Rules;
19
+ };
20
+ export type ExecuteQueryParams = {
21
+ currentMethod: ReturnType<GetOperatorsFunction>[keyof ReturnType<GetOperatorsFunction>];
22
+ query: Parameters<GetOperatorsFunction>;
23
+ update: Document;
24
+ document: Document;
25
+ };
26
+ type FunctionsControllerOptions = {
27
+ functionsList: Functions;
28
+ rules: Rules;
29
+ };
30
+ export type FunctionController = (app: FastifyInstance, { functionsList, rules }: FunctionsControllerOptions) => Promise<void>;
31
+ export {};
32
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/functions/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAEhD,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,aAAa,EAAE,SAAS,CAAA;IACxB,SAAS,EAAE,KAAK,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACvF,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACvC,MAAM,EAAE,QAAQ,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,aAAa,EAAE,SAAS,CAAA;IACxB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,eAAe,EACpB,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE,0BAA0B,KACjD,OAAO,CAAC,IAAI,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });