@flowerforce/flowerbase 1.0.1-beta.3

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 +122 -0
  22. package/dist/constants.d.ts +18 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/constants.js +34 -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 +85 -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 +57 -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 +84 -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 +50 -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 +84 -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 +63 -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 +165 -0
  203. package/src/babel.config.json +3 -0
  204. package/src/constants.ts +22 -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 +72 -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 +34 -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 +75 -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 +52 -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 +97 -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,74 @@
1
+ import { mongodb } from '@fastify/mongodb';
2
+ import { Arguments } from '../../auth/dtos';
3
+ import { GenerateContextDataParams } from './interface';
4
+ /**
5
+ * > Used to generate the current context data
6
+ * @testable
7
+ * @param user -> the current user
8
+ * @param services -> the list of all services
9
+ * @param app -> the fastify instance
10
+ * @param rules -> the rules object
11
+ * @param currentFunction -> the function's name that should be called
12
+ * @param functionsList -> the list of all functions
13
+ */
14
+ export declare const generateContextData: ({ user, services, app, rules, currentFunction, functionsList, GenerateContext }: GenerateContextDataParams) => {
15
+ BSON: typeof mongodb.BSON;
16
+ console: {
17
+ log: (...args: Arguments) => void;
18
+ };
19
+ context: {
20
+ user: unknown;
21
+ environment: {
22
+ tag: string | undefined;
23
+ };
24
+ values: {
25
+ get: (key: string) => string | undefined;
26
+ };
27
+ services: {
28
+ get: (serviceName: keyof typeof services) => {
29
+ db: (dbName: string) => {
30
+ collection: (collName: string) => ReturnType<import("../../services/mongodb-atlas/model").GetOperatorsFunction>;
31
+ };
32
+ } | {
33
+ get: <T = null>({ url, headers }: import("../../services/api/model").GetParams) => Promise<{
34
+ status: number;
35
+ headers: import("undici/types/header").IncomingHttpHeaders;
36
+ body: {
37
+ message: string;
38
+ };
39
+ } | import("undici").Dispatcher.ResponseData<T>>;
40
+ post: <T = null>({ scheme, host, path, url: currentUrl, headers, body, encodeBodyAsJSON }: import("../../services/api/model").PostParams) => Promise<{
41
+ status: number;
42
+ headers: import("undici/types/header").IncomingHttpHeaders;
43
+ body: {
44
+ message: string;
45
+ };
46
+ } | import("undici").Dispatcher.ResponseData<T>>;
47
+ put: <T = null>({ scheme, host, path, url: currentUrl, headers, body, encodeBodyAsJSON }: import("../../services/api/model").PutParams) => Promise<{
48
+ status: number;
49
+ headers: import("undici/types/header").IncomingHttpHeaders;
50
+ body: {
51
+ message: string;
52
+ };
53
+ } | import("undici").Dispatcher.ResponseData<T>>;
54
+ delete: <T = null>({ scheme, host, path, url: currentUrl, headers }: import("../../services/api/model").DeleteParams) => Promise<{
55
+ status: number;
56
+ headers: import("undici/types/header").IncomingHttpHeaders;
57
+ body: {
58
+ message: string;
59
+ };
60
+ } | import("undici").Dispatcher.ResponseData<T>>;
61
+ } | {
62
+ lambda: (region: string) => import("aws-sdk").Lambda & {
63
+ Invoke: (...args: Parameters<import("aws-sdk").Lambda["invoke"]>) => Promise<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/lambda").InvocationResponse, import("aws-sdk").AWSError>>;
64
+ InvokeAsync: import("aws-sdk").Lambda["invokeAsync"];
65
+ };
66
+ s3: (region: string) => import("aws-sdk").S3;
67
+ } | undefined;
68
+ };
69
+ functions: {
70
+ execute: (name: keyof typeof functionsList, ...args: Arguments) => Promise<void>;
71
+ };
72
+ };
73
+ };
74
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,iFAQjC,yBAAyB;;;uBAGT,SAAS;;;;;;;;uBAUX,MAAM;;;+BAGE,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA1BpC,GAAE;;;;;;;4BA2CU,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAclE,CAAA"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateContextData = void 0;
4
+ const mongodb_1 = require("@fastify/mongodb");
5
+ /**
6
+ * > Used to generate the current context data
7
+ * @testable
8
+ * @param user -> the current user
9
+ * @param services -> the list of all services
10
+ * @param app -> the fastify instance
11
+ * @param rules -> the rules object
12
+ * @param currentFunction -> the function's name that should be called
13
+ * @param functionsList -> the list of all functions
14
+ */
15
+ const generateContextData = ({ user, services, app, rules, currentFunction, functionsList, GenerateContext }) => ({
16
+ BSON: mongodb_1.mongodb.BSON,
17
+ console: {
18
+ log: (...args) => {
19
+ console.log(...args);
20
+ }
21
+ },
22
+ context: {
23
+ user,
24
+ environment: {
25
+ tag: process.env.NODE_ENV
26
+ },
27
+ values: {
28
+ get: (key) => process.env[key],
29
+ },
30
+ services: {
31
+ get: (serviceName) => {
32
+ try {
33
+ return services[serviceName](app, {
34
+ rules,
35
+ user,
36
+ run_as_system: currentFunction.run_as_system
37
+ });
38
+ }
39
+ catch (error) {
40
+ console.error('Something went wrong while generating context function', serviceName, error);
41
+ }
42
+ }
43
+ },
44
+ functions: {
45
+ execute: (name, ...args) => {
46
+ const currentFunction = functionsList[name];
47
+ return GenerateContext({
48
+ args,
49
+ app,
50
+ rules,
51
+ user,
52
+ currentFunction,
53
+ functionsList,
54
+ services
55
+ });
56
+ }
57
+ }
58
+ }
59
+ });
60
+ exports.generateContextData = generateContextData;
@@ -0,0 +1,14 @@
1
+ import { GenerateContextParams } from './interface';
2
+ /**
3
+ * > Used to generate the current context
4
+ * @testable
5
+ * @param args -> generic arguments
6
+ * @param app -> the fastify instance
7
+ * @param rules -> the rules object
8
+ * @param user -> the current user
9
+ * @param currentFunction -> the function's name that should be called
10
+ * @param functionsList -> the list of all functions
11
+ * @param services -> the list of all services
12
+ */
13
+ export declare function GenerateContext({ args, app, rules, user, currentFunction, functionsList, services }: GenerateContextParams): Promise<any>;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/context/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,EACpC,IAAI,EACJ,GAAG,EACH,KAAK,EACL,IAAI,EACJ,eAAe,EACf,aAAa,EACb,QAAQ,EACT,EAAE,qBAAqB,gBA0BvB"}
@@ -0,0 +1,50 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GenerateContext = GenerateContext;
16
+ const module_1 = __importDefault(require("module"));
17
+ const vm_1 = __importDefault(require("vm"));
18
+ const bson_1 = require("bson");
19
+ const helpers_1 = require("./helpers");
20
+ /**
21
+ * > Used to generate the current context
22
+ * @testable
23
+ * @param args -> generic arguments
24
+ * @param app -> the fastify instance
25
+ * @param rules -> the rules object
26
+ * @param user -> the current user
27
+ * @param currentFunction -> the function's name that should be called
28
+ * @param functionsList -> the list of all functions
29
+ * @param services -> the list of all services
30
+ */
31
+ function GenerateContext(_a) {
32
+ return __awaiter(this, arguments, void 0, function* ({ args, app, rules, user, currentFunction, functionsList, services }) {
33
+ const contextData = (0, helpers_1.generateContextData)({
34
+ user,
35
+ services,
36
+ app,
37
+ rules,
38
+ currentFunction,
39
+ functionsList,
40
+ GenerateContext
41
+ });
42
+ try {
43
+ vm_1.default.runInContext(module_1.default.wrap(currentFunction.code), vm_1.default.createContext(contextData))(exports, require, module, __filename, __dirname);
44
+ }
45
+ catch (e) {
46
+ console.log(e);
47
+ }
48
+ return yield module.exports(...bson_1.EJSON.deserialize(args));
49
+ });
50
+ }
@@ -0,0 +1,18 @@
1
+ import { FastifyInstance } from 'fastify';
2
+ import { Arguments, User } from '../../auth/dtos';
3
+ import { Function, Functions } from '../../features/functions/interface';
4
+ import { Rules } from '../../features/rules/interface';
5
+ import { Services } from '../../services/interface';
6
+ export interface GenerateContextParams {
7
+ app: FastifyInstance;
8
+ currentFunction: Function;
9
+ functionsList: Functions;
10
+ rules: Rules;
11
+ user: User;
12
+ services: Services;
13
+ args: Arguments;
14
+ }
15
+ export interface GenerateContextDataParams extends Omit<GenerateContextParams, 'args'> {
16
+ GenerateContext: (params: GenerateContextParams) => Promise<void>;
17
+ }
18
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/utils/context/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,eAAe,EAAE,QAAQ,CAAA;IACzB,aAAa,EAAE,SAAS,CAAA;IACxB,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,SAAS,CAAA;CAChB;AAED,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACpF,eAAe,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAClE"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * > Creates the hash for a string
3
+ * @param plaintext -> the string that should be encrypted
4
+ * @tested
5
+ */
6
+ export declare const hashPassword: (plaintext: string) => Promise<string>;
7
+ /**
8
+ * > Compares two strings
9
+ * @param plaintext -> the first string
10
+ * @param storedPassword -> the second string
11
+ * @tested
12
+ */
13
+ export declare const comparePassword: (plaintext: string, storedPassword: string) => Promise<boolean>;
14
+ /**
15
+ * > Generate a random token
16
+ * @param length -> the token length
17
+ */
18
+ export declare const generateToken: (length?: number) => string;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/crypto/index.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,WAAW,MAAM,oBAInD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAU,WAAW,MAAM,EAAE,gBAAgB,MAAM,qBAK9E,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,eAAW,WAExC,CAAA"}
@@ -0,0 +1,50 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.generateToken = exports.comparePassword = exports.hashPassword = void 0;
16
+ const node_crypto_1 = __importDefault(require("node:crypto"));
17
+ const node_util_1 = require("node:util");
18
+ const scrypt = (0, node_util_1.promisify)(node_crypto_1.default.scrypt);
19
+ /**
20
+ * > Creates the hash for a string
21
+ * @param plaintext -> the string that should be encrypted
22
+ * @tested
23
+ */
24
+ const hashPassword = (plaintext) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const salt = node_crypto_1.default.randomBytes(128).toString('hex');
26
+ const buffer = (yield scrypt(plaintext, salt, 64));
27
+ return `${buffer.toString('hex')}.${salt}`;
28
+ });
29
+ exports.hashPassword = hashPassword;
30
+ /**
31
+ * > Compares two strings
32
+ * @param plaintext -> the first string
33
+ * @param storedPassword -> the second string
34
+ * @tested
35
+ */
36
+ const comparePassword = (plaintext, storedPassword) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const [storedHash, storedSalt] = storedPassword.split('.');
38
+ const storedBuffer = Buffer.from(storedHash, 'hex');
39
+ const buffer = (yield scrypt(plaintext, storedSalt, 64));
40
+ return node_crypto_1.default.timingSafeEqual(buffer, storedBuffer);
41
+ });
42
+ exports.comparePassword = comparePassword;
43
+ /**
44
+ * > Generate a random token
45
+ * @param length -> the token length
46
+ */
47
+ const generateToken = (length = 32) => {
48
+ return node_crypto_1.default.randomBytes(length).toString('hex');
49
+ };
50
+ exports.generateToken = generateToken;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Asynchronously checks if at least one element in the array satisfies the given asynchronous callback function.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param {T[]} array - The array to iterate over.
6
+ * @param {(element: T, index: number, arr: T[]) => Promise<boolean>} callback - An asynchronous function that takes an element, its index, and the original array,
7
+ * and returns a Promise resolving to `true` if the condition is met, otherwise `false`.
8
+ * @returns {Promise<boolean>} A promise that resolves to `true` if at least one element satisfies the callback condition, otherwise `false`.
9
+ * @tested
10
+ */
11
+ export declare function someAsync<T>(array: T[], callback: (element: T, index: number, arr: T[]) => Promise<boolean>): Promise<boolean>;
12
+ //# sourceMappingURL=someAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"someAsync.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers/someAsync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GACpE,OAAO,CAAC,OAAO,CAAC,CAUlB"}
@@ -0,0 +1,56 @@
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 __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.someAsync = someAsync;
20
+ /**
21
+ * Asynchronously checks if at least one element in the array satisfies the given asynchronous callback function.
22
+ *
23
+ * @template T - The type of elements in the array.
24
+ * @param {T[]} array - The array to iterate over.
25
+ * @param {(element: T, index: number, arr: T[]) => Promise<boolean>} callback - An asynchronous function that takes an element, its index, and the original array,
26
+ * and returns a Promise resolving to `true` if the condition is met, otherwise `false`.
27
+ * @returns {Promise<boolean>} A promise that resolves to `true` if at least one element satisfies the callback condition, otherwise `false`.
28
+ * @tested
29
+ */
30
+ function someAsync(array, callback) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ var _a, array_1, array_1_1;
33
+ var _b, e_1, _c, _d;
34
+ let i = 0;
35
+ try {
36
+ for (_a = true, array_1 = __asyncValues(array); array_1_1 = yield array_1.next(), _b = array_1_1.done, !_b; _a = true) {
37
+ _d = array_1_1.value;
38
+ _a = false;
39
+ const el = _d;
40
+ const isValid = yield callback(el, i, array);
41
+ if (isValid) {
42
+ return true;
43
+ }
44
+ i++;
45
+ }
46
+ }
47
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
48
+ finally {
49
+ try {
50
+ if (!_a && !_b && (_c = array_1.return)) yield _c.call(array_1);
51
+ }
52
+ finally { if (e_1) throw e_1.error; }
53
+ }
54
+ return false;
55
+ });
56
+ }
@@ -0,0 +1,3 @@
1
+ export declare const readFileContent: (filePath: string) => string;
2
+ export declare const readJsonContent: (filePath: string) => unknown;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,WAAuC,CAAA;AACvF,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,KACL,OAAO,CAAA"}
@@ -0,0 +1,11 @@
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.readJsonContent = exports.readFileContent = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const readFileContent = (filePath) => fs_1.default.readFileSync(filePath, 'utf-8');
9
+ exports.readFileContent = readFileContent;
10
+ const readJsonContent = (filePath) => JSON.parse((0, exports.readFileContent)(filePath));
11
+ exports.readJsonContent = readJsonContent;
@@ -0,0 +1,8 @@
1
+ import { FastifyInstance } from 'fastify';
2
+ /**
3
+ * > Used to expose all app routes
4
+ * @param fastify -> the fastify instance
5
+ * @tested
6
+ */
7
+ export declare const exposeRoutes: (fastify: FastifyInstance) => Promise<void>;
8
+ //# sourceMappingURL=exposeRoutes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exposeRoutes.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/exposeRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAGzC;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,SAAS,eAAe,kBAgB1D,CAAA"}
@@ -0,0 +1,41 @@
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.exposeRoutes = void 0;
13
+ const node_process_1 = require("node:process");
14
+ const constants_1 = require("../../constants");
15
+ /**
16
+ * > Used to expose all app routes
17
+ * @param fastify -> the fastify instance
18
+ * @tested
19
+ */
20
+ const exposeRoutes = (fastify) => __awaiter(void 0, void 0, void 0, function* () {
21
+ try {
22
+ fastify.get(`${constants_1.API_VERSION}/app/:appId/location`, (req) => __awaiter(void 0, void 0, void 0, function* () {
23
+ return ({
24
+ deployment_model: 'LOCAL',
25
+ location: 'IE',
26
+ hostname: `http://${req.headers.host}`,
27
+ ws_hostname: `wss://${req.headers.host}`
28
+ });
29
+ }));
30
+ fastify.get('/health', () => __awaiter(void 0, void 0, void 0, function* () {
31
+ return ({
32
+ status: 'ok',
33
+ uptime: (0, node_process_1.uptime)()
34
+ });
35
+ }));
36
+ }
37
+ catch (e) {
38
+ console.error('Error while exposing routes', e.message);
39
+ }
40
+ });
41
+ exports.exposeRoutes = exposeRoutes;
@@ -0,0 +1,19 @@
1
+ import { FastifyInstance } from 'fastify';
2
+ import { Functions } from '../../features/functions/interface';
3
+ type RegisterFunction = FastifyInstance['register'];
4
+ type RegisterPluginsParams = {
5
+ register: RegisterFunction;
6
+ mongodbUrl: string;
7
+ jwtSecret: string;
8
+ functionsList: Functions;
9
+ };
10
+ /**
11
+ * > Used to register all plugins
12
+ * @param register -> the fastify register method
13
+ * @param mongodbUrl -> the database connection string
14
+ * @param jwtSecret -> connection jwt
15
+ * @tested
16
+ */
17
+ export declare const registerPlugins: ({ register, mongodbUrl, jwtSecret, functionsList }: RegisterPluginsParams) => Promise<void>;
18
+ export {};
19
+ //# sourceMappingURL=registerPlugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerPlugins.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/registerPlugins.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAKzC,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AAE9D,KAAK,gBAAgB,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;AAGnD,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAOD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAU,oDAKnC,qBAAqB,kBAcvB,CAAA"}
@@ -0,0 +1,84 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.registerPlugins = void 0;
16
+ const cors_1 = __importDefault(require("@fastify/cors"));
17
+ const mongodb_1 = __importDefault(require("@fastify/mongodb"));
18
+ const controller_1 = require("../../auth/controller");
19
+ const jwt_1 = __importDefault(require("../../auth/plugins/jwt"));
20
+ const controller_2 = require("../../auth/providers/local-userpass/controller");
21
+ const constants_1 = require("../../constants");
22
+ /**
23
+ * > Used to register all plugins
24
+ * @param register -> the fastify register method
25
+ * @param mongodbUrl -> the database connection string
26
+ * @param jwtSecret -> connection jwt
27
+ * @tested
28
+ */
29
+ const registerPlugins = (_a) => __awaiter(void 0, [_a], void 0, function* ({ register, mongodbUrl, jwtSecret, functionsList }) {
30
+ try {
31
+ const registersConfig = yield getRegisterConfig({
32
+ mongodbUrl,
33
+ jwtSecret,
34
+ functionsList
35
+ });
36
+ registersConfig.forEach(({ plugin, options }) => {
37
+ register(plugin, options);
38
+ });
39
+ }
40
+ catch (e) {
41
+ console.error('Error while registering plugins', e.message);
42
+ }
43
+ });
44
+ exports.registerPlugins = registerPlugins;
45
+ /**
46
+ * > Used to generate the register congig
47
+ * @param mongodbUrl -> the database connection string
48
+ * @param jwtSecret -> connection jwt
49
+ * @testable
50
+ */
51
+ const getRegisterConfig = (_a) => __awaiter(void 0, [_a], void 0, function* ({ mongodbUrl, jwtSecret }) {
52
+ return [
53
+ {
54
+ plugin: cors_1.default,
55
+ options: {
56
+ origin: '*',
57
+ methods: ['POST', 'GET']
58
+ }
59
+ },
60
+ {
61
+ plugin: mongodb_1.default,
62
+ options: {
63
+ forceClose: true,
64
+ url: mongodbUrl
65
+ }
66
+ },
67
+ {
68
+ plugin: jwt_1.default,
69
+ options: {
70
+ secret: jwtSecret
71
+ }
72
+ },
73
+ {
74
+ plugin: controller_1.authController,
75
+ options: { prefix: `${constants_1.API_VERSION}/auth` }
76
+ },
77
+ {
78
+ plugin: controller_2.localUserPassController,
79
+ options: {
80
+ prefix: `${constants_1.API_VERSION}/app/:appId/auth/providers/local-userpass`
81
+ }
82
+ }
83
+ ];
84
+ });
@@ -0,0 +1,4 @@
1
+ import { PermissionExpression } from './interface';
2
+ import { MachineContext } from './machines/interface';
3
+ export declare const evaluateExpression: (params: MachineContext["params"], expression?: PermissionExpression, user?: MachineContext["user"]) => Promise<boolean>;
4
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/roles/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAIrD,eAAO,MAAM,kBAAkB,GAAU,QAAQ,cAAc,CAAC,QAAQ,CAAC,EAAE,aAAa,oBAAoB,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,KAAG,OAAO,CAAC,OAAO,CAa5J,CAAA"}
@@ -0,0 +1,47 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.evaluateExpression = void 0;
16
+ const services_1 = require("../../services");
17
+ const state_1 = require("../../state");
18
+ const context_1 = require("../context");
19
+ const rules_1 = require("../rules");
20
+ const utils_1 = __importDefault(require("../rules-matcher/utils"));
21
+ const functionsConditions = ["%%true", "%%false"];
22
+ const evaluateExpression = (params, expression, user) => __awaiter(void 0, void 0, void 0, function* () {
23
+ if (!expression || typeof expression === 'boolean')
24
+ return !!expression;
25
+ const value = Object.assign(Object.assign(Object.assign({}, params.expansions), params.cursor), { "%%user": user, '%%true': true });
26
+ const conditions = (0, rules_1.expandQuery)(expression, value);
27
+ const complexCondition = Object.entries(conditions).find(([key]) => functionsConditions.includes(key));
28
+ return complexCondition ? yield evaluateComplexExpression(complexCondition, params, user) : utils_1.default.checkRule(conditions, value, {});
29
+ });
30
+ exports.evaluateExpression = evaluateExpression;
31
+ const evaluateComplexExpression = (condition, params, user) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const [key, config] = condition;
33
+ const { name } = config["%function"];
34
+ const functionsList = state_1.StateManager.select("functions");
35
+ const app = state_1.StateManager.select("app");
36
+ const currentFunction = functionsList[name];
37
+ const response = yield (0, context_1.GenerateContext)({
38
+ args: [params.cursor],
39
+ app,
40
+ rules: {},
41
+ user,
42
+ currentFunction,
43
+ functionsList,
44
+ services: services_1.services
45
+ });
46
+ return key === "%%true" ? response : !response;
47
+ });