@ozdao/prometheus-framework 0.2.30 → 0.2.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. package/dist/addMembersQuantity-3505b6f3.mjs +98 -0
  2. package/dist/addMembersQuantity-fb552ca0.js +97 -0
  3. package/dist/auth.server.js +6 -9
  4. package/dist/auth.server.mjs +6 -9
  5. package/dist/community.server.js +28 -21
  6. package/dist/community.server.mjs +28 -21
  7. package/dist/events.server.js +1 -1
  8. package/dist/events.server.mjs +1 -1
  9. package/dist/files.server.js +114 -111
  10. package/dist/files.server.mjs +114 -111
  11. package/dist/gallery.server.js +3 -3
  12. package/dist/gallery.server.mjs +3 -3
  13. package/dist/globals.server.js +1 -1
  14. package/dist/globals.server.mjs +1 -1
  15. package/dist/index-a8dffc0c.js +213 -0
  16. package/dist/index-d769324d.mjs +214 -0
  17. package/dist/mailing-37c2ba41.mjs +68 -0
  18. package/dist/mailing-fe16a26a.js +67 -0
  19. package/dist/main.css +1 -1
  20. package/dist/middlewares.server.js +1 -1
  21. package/dist/middlewares.server.mjs +1 -1
  22. package/dist/organizations.server.js +125 -25
  23. package/dist/organizations.server.mjs +125 -25
  24. package/dist/prometheus-framework.cjs.js +30 -29
  25. package/dist/prometheus-framework.es.js +2478 -2282
  26. package/dist/reports.server.js +1 -1
  27. package/dist/reports.server.mjs +1 -1
  28. package/dist/users.server.js +1 -1
  29. package/dist/users.server.mjs +1 -1
  30. package/package.json +4 -2
  31. package/src/assets/images/logo.svg +7 -7
  32. package/src/components/Block/Block.vue +77 -0
  33. package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -2
  34. package/src/components/Button/Button.vue +32 -227
  35. package/src/components/Checkbox/Checkbox.vue +1 -1
  36. package/src/components/Chips/Chips.vue +8 -8
  37. package/src/components/DatePicker/DatePicker.vue +3 -4
  38. package/src/components/EditImages/EditImages.vue +32 -14
  39. package/src/{modules/globals/components/sections → components/Feed}/Feed.vue +60 -45
  40. package/src/components/FieldBig/FieldBig.vue +16 -5
  41. package/src/components/FieldPhone/FieldPhone.vue +2 -1
  42. package/src/components/Footer/Footer.vue +36 -27
  43. package/src/components/Header/Header.vue +161 -166
  44. package/src/components/Loader/Loader.vue +9 -2
  45. package/src/components/LocationMarker/LocationMarker.vue +38 -12
  46. package/src/components/LocationSelection/LocationSelection.vue +67 -75
  47. package/src/components/Magnifier/Magnifier.vue +3 -3
  48. package/src/components/Navigation/Navigation.vue +16 -16
  49. package/src/components/Popup/Popup.vue +8 -6
  50. package/src/components/Select/Select.vue +35 -6
  51. package/src/components/SelectMulti/SelectMulti.vue +5 -13
  52. package/src/components/Shader/Shader.vue +128 -0
  53. package/src/components/Sidebar/Sidebar.vue +71 -35
  54. package/src/components/Spoiler/Spoiler.vue +1 -1
  55. package/src/components/Tab/Tab.vue +1 -1
  56. package/src/components/Tooltip/Tooltip.vue +1 -1
  57. package/src/components/UploadImage/UploadImage.vue +4 -4
  58. package/src/components/UploadImageMultiple/UploadImageMultiple.vue +54 -10
  59. package/src/modules/applications/controllers/applications.controller.js +0 -1
  60. package/src/modules/auth/components/pages/EnterCode.vue +1 -1
  61. package/src/modules/auth/components/pages/EnterPassword.vue +3 -3
  62. package/src/modules/auth/components/pages/ResetPassword.vue +1 -2
  63. package/src/modules/auth/components/pages/SignIn.vue +26 -10
  64. package/src/modules/auth/components/pages/SignUp.vue +1 -2
  65. package/src/modules/auth/controllers/twofa.controller.js +4 -4
  66. package/src/modules/auth/localization/EnterCode.json +2 -2
  67. package/src/modules/auth/localization/EnterPassword.json +2 -2
  68. package/src/modules/auth/localization/ResetPassword.json +2 -2
  69. package/src/modules/auth/localization/SignIn.json +3 -3
  70. package/src/modules/auth/localization/SignUp.json +3 -3
  71. package/src/modules/auth/utils/server/verifyAppleIdToken.js +0 -1
  72. package/src/modules/backoffice/components/layouts/Backoffice.vue +1 -1
  73. package/src/modules/backoffice/components/pages/Dashboard.vue +171 -120
  74. package/src/modules/backoffice/router/backoffice.js +119 -129
  75. package/src/modules/chats/components/blocks/ChatMessage.vue +25 -0
  76. package/src/modules/chats/components/pages/ChatPage.vue +50 -0
  77. package/src/modules/chats/components/sections/ChatWindow.vue +38 -0
  78. package/src/modules/chats/controllers/chats.controller.js +32 -0
  79. package/src/modules/chats/models/chat.model.js +26 -0
  80. package/src/modules/chats/routes/chats.routes.js +53 -0
  81. package/src/modules/chats/store/chat.store.js +61 -0
  82. package/src/modules/community/components/blocks/CardBlogpost.vue +19 -4
  83. package/src/modules/community/components/layouts/Community.vue +96 -39
  84. package/src/modules/community/components/pages/Blog.vue +4 -3
  85. package/src/modules/community/components/pages/BlogPost.vue +10 -1
  86. package/src/modules/community/components/pages/CreateBlogPost.vue +36 -17
  87. package/src/modules/community/components/sections/HotPosts.vue +3 -3
  88. package/src/modules/community/components/sections/JoinUs.vue +19 -13
  89. package/src/modules/community/controllers/blog.controller.js +3 -4
  90. package/src/modules/community/controllers/utils/queryProcessor.js +16 -17
  91. package/src/modules/community/models/blogpost.model.js +6 -3
  92. package/src/modules/community/store/blogposts.js +1 -0
  93. package/src/modules/constructor/components/elements/Embed.vue +12 -1
  94. package/src/modules/constructor/components/elements/ImageUpload.vue +2 -2
  95. package/src/modules/constructor/components/elements/Textarea.vue +6 -1
  96. package/src/modules/constructor/components/elements/Video.vue +79 -0
  97. package/src/modules/constructor/components/elements/VideoPlayer.vue +59 -0
  98. package/src/modules/constructor/components/elements/Youtube.vue +52 -0
  99. package/src/modules/constructor/components/sections/Constructor.vue +27 -3
  100. package/src/modules/events/components/layouts/layoutEvents.vue +7 -28
  101. package/src/modules/files/controllers/files.controller.js +9 -22
  102. package/src/modules/files/middlewares/server/index.js +2 -2
  103. package/src/modules/files/middlewares/server/middlewareBusboy.js +137 -0
  104. package/src/modules/files/routes/files.routes.js +9 -9
  105. package/src/modules/globals/localization/vue-i18n.js +8 -1
  106. package/src/modules/globals/mixins/mixins.js +23 -13
  107. package/src/modules/globals/router/routerGuards.js +2 -2
  108. package/src/modules/globals/store/globals.js +86 -9
  109. package/src/modules/globals/utils/mailing.js +24 -3
  110. package/src/modules/icons/entities/IconCommunity.vue +4 -4
  111. package/src/modules/icons/entities/IconEvents.vue +1 -1
  112. package/src/modules/icons/entities/IconGroups.vue +1 -1
  113. package/src/modules/icons/entities/IconPrice.vue +5 -0
  114. package/src/modules/icons/entities/IconProfile.vue +5 -0
  115. package/src/modules/icons/entities/IconShopcart.vue +5 -0
  116. package/src/modules/icons/entities/IconTime.vue +5 -0
  117. package/src/modules/icons/icons.client.js +4 -0
  118. package/src/modules/icons/labels/LabelAppStore.vue +24 -24
  119. package/src/modules/icons/labels/LabelGooglePlay.vue +9 -9
  120. package/src/modules/icons/logos/Logotype.vue +20 -0
  121. package/src/modules/icons/navigation/IconAdd.vue +17 -0
  122. package/src/modules/icons/navigation/IconChevronBottom.vue +18 -0
  123. package/src/modules/icons/navigation/IconChevronRight.vue +3 -3
  124. package/src/modules/icons/navigation/IconDelete.vue +19 -0
  125. package/src/modules/icons/navigation/IconMinus.vue +15 -0
  126. package/src/modules/icons/navigation/IconSearch.vue +17 -0
  127. package/src/modules/icons/navigation/IconUpload.vue +16 -0
  128. package/src/modules/icons/placeholders/PlaceholderImage.vue +5 -0
  129. package/src/modules/icons/placeholders/PlaceholderOrganizationPic.vue +20 -0
  130. package/src/modules/icons/placeholders/PlaceholderUserpic.vue +4 -18
  131. package/src/modules/icons/socials/instagram.vue +1 -1
  132. package/src/modules/icons/socials/line.vue +1 -1
  133. package/src/modules/icons/socials/reddit.vue +1 -1
  134. package/src/modules/icons/socials/telegram.vue +1 -1
  135. package/src/modules/icons/socials/twitter.vue +1 -1
  136. package/src/modules/icons/socials/youtube.vue +1 -1
  137. package/src/modules/landing/components/sections/Guide.vue +92 -0
  138. package/src/modules/landing/components/sections/MobileApp.vue +23 -12
  139. package/src/modules/marketplace/components/layouts/Marketplace.vue +76 -188
  140. package/src/modules/marketplace/components/pages/Catalog.vue +65 -119
  141. package/src/modules/marketplace/components/sections/Filters.vue +195 -0
  142. package/src/modules/marketplace/store/marketplace.js +2 -2
  143. package/src/modules/middlewares/client/auth.validation.js +0 -6
  144. package/src/modules/middlewares/client/states.validation.js +2 -8
  145. package/src/modules/middlewares/server/authJwt.js +1 -1
  146. package/src/modules/mobile/components/Menu/MenuItem.vue +3 -6
  147. package/src/modules/openai/controllers/openai.controller.js +0 -1
  148. package/src/modules/orders/components/blocks/CardOrder.vue +166 -0
  149. package/src/modules/orders/components/blocks/CardOrderItem.vue +59 -66
  150. package/src/modules/orders/components/blocks/Positions.vue +4 -4
  151. package/src/modules/orders/components/pages/EditOrder.vue +78 -142
  152. package/src/modules/orders/components/pages/FormOrder.vue +192 -0
  153. package/src/modules/orders/components/pages/Order.vue +326 -120
  154. package/src/modules/orders/components/pages/Orders.vue +13 -9
  155. package/src/modules/orders/components/pages/{ViewOrder.vue → Orders_refact.vue} +13 -10
  156. package/src/modules/orders/components/partials/ShopCart.vue +22 -13
  157. package/src/modules/orders/components/sections/EmptyState.vue +1 -1
  158. package/src/modules/orders/components/sections/{Form.vue → FormOrderDetails.vue} +38 -106
  159. package/src/modules/orders/controllers/orders.controller.js +37 -28
  160. package/src/modules/orders/models/order.model.js +39 -9
  161. package/src/modules/orders/router/orders.router.js +23 -2
  162. package/src/modules/orders/routes/orders.routes.js +14 -17
  163. package/src/modules/orders/store/orders.js +24 -9
  164. package/src/modules/orders/store/shopcart.js +20 -19
  165. package/src/modules/organizations/components/blocks/CardDepartment.vue +1 -1
  166. package/src/modules/organizations/components/blocks/CardOrganization.vue +98 -46
  167. package/src/modules/organizations/components/blocks/Rating.vue +1 -1
  168. package/src/modules/organizations/components/blocks/Socials.vue +11 -3
  169. package/src/modules/organizations/components/elements/ButtonToggleMembership.vue +1 -1
  170. package/src/modules/organizations/components/pages/Department.vue +1 -1
  171. package/src/modules/organizations/components/pages/DepartmentEdit.vue +4 -4
  172. package/src/modules/organizations/components/pages/Members.vue +6 -4
  173. package/src/modules/organizations/components/pages/Organization.vue +120 -49
  174. package/src/modules/organizations/components/pages/OrganizationEdit.vue +8 -1
  175. package/src/modules/organizations/components/pages/Organizations.vue +27 -6
  176. package/src/modules/organizations/components/sections/DetailsTab.vue +11 -9
  177. package/src/modules/organizations/components/sections/Feed.vue +0 -3
  178. package/src/modules/organizations/components/sections/FeedDepartments.vue +2 -2
  179. package/src/modules/organizations/controllers/organizations.controller.js +126 -15
  180. package/src/modules/organizations/controllers/utils/addMembersQuantity.js +19 -9
  181. package/src/modules/organizations/models/organization.model.js +5 -2
  182. package/src/modules/organizations/router/members.router.js +1 -3
  183. package/src/modules/organizations/router/organizations.js +8 -6
  184. package/src/modules/organizations/router/products.router.js +36 -2
  185. package/src/modules/organizations/store/organizations.js +38 -84
  186. package/src/modules/pages/controllers/pages.controller.js +0 -4
  187. package/src/modules/payments/controller/payments.controller.js +1 -1
  188. package/src/modules/products/components/blocks/CardLeftover.vue +17 -22
  189. package/src/modules/products/components/blocks/CardPosition.vue +96 -49
  190. package/src/modules/products/components/blocks/CardProduct.vue +24 -53
  191. package/src/modules/products/components/blocks/Images360.vue +4 -4
  192. package/src/modules/products/components/blocks/ImagesThumbnails.vue +2 -7
  193. package/src/modules/products/components/blocks/ListPositions.vue +74 -0
  194. package/src/modules/products/components/elements/Price.vue +11 -5
  195. package/src/modules/products/components/elements/THC.vue +6 -6
  196. package/src/modules/products/components/pages/{LeftoverAdd.vue → EditLeftover.vue} +93 -79
  197. package/src/modules/products/components/pages/Leftovers.vue +74 -70
  198. package/src/modules/products/components/pages/Product.vue +4 -7
  199. package/src/modules/products/components/pages/ProductEdit.vue +230 -88
  200. package/src/modules/products/components/pages/ProductRecommmendation.vue +1 -1
  201. package/src/modules/products/components/pages/Products.vue +6 -3
  202. package/src/modules/products/components/pages/ProductsBackoffice.vue +3 -5
  203. package/src/modules/products/components/sections/EditModifications.vue +3 -3
  204. package/src/modules/products/components/sections/EditProductInfo.vue +40 -50
  205. package/src/modules/products/components/sections/FilterProducts.vue +57 -18
  206. package/src/modules/products/components/sections/HeroRecommendation.vue +233 -99
  207. package/src/modules/products/components/sections/MenuSection.vue +127 -0
  208. package/src/modules/products/components/sections/PopularProducts.vue +81 -37
  209. package/src/modules/products/components/sections/SectionProduct.vue +21 -23
  210. package/src/modules/products/controllers/leftovers.controller.js +11 -1
  211. package/src/modules/products/controllers/products.controller.js +100 -97
  212. package/src/modules/products/models/leftover.model.js +6 -4
  213. package/src/modules/products/models/product.model.js +13 -1
  214. package/src/modules/products/routes/products.routes.js +4 -4
  215. package/src/modules/products/store/leftovers.js +4 -24
  216. package/src/modules/products/store/products.js +44 -30
  217. package/src/modules/spots/components/blocks/CardSpot.vue +43 -72
  218. package/src/modules/spots/components/layouts/Spots.vue +9 -91
  219. package/src/modules/spots/components/pages/Map.vue +171 -62
  220. package/src/modules/spots/components/pages/Spot.vue +1 -1
  221. package/src/modules/spots/components/pages/SpotEdit.vue +131 -174
  222. package/src/modules/spots/controllers/spots.controller.js +1 -0
  223. package/src/modules/spots/models/spot.model.js +6 -3
  224. package/src/modules/spots/store/spots.js +42 -48
  225. package/src/modules/users/components/pages/Profile.vue +6 -28
  226. package/src/modules/users/components/pages/ProfileBlogposts.vue +1 -1
  227. package/src/modules/users/components/pages/ProfileEdit.vue +1 -1
  228. package/src/modules/users/components/pages/ProfileEvents.vue +1 -1
  229. package/src/modules/users/components/pages/ProfileOrganizations.vue +1 -1
  230. package/src/modules/users/router/users.js +1 -1
  231. package/src/modules/wallet/components/pages/Wallet.vue +105 -109
  232. package/src/modules/wallet/controllers/crypto.controller.js +129 -0
  233. package/src/modules/wallet/models/reward.model.js +53 -0
  234. package/src/modules/wallet/routes/crypto.routes.js +36 -0
  235. package/src/modules/wallet/store/wallet.js +52 -49
  236. package/src/styles/base/all.scss +143 -11
  237. package/src/styles/base/backgrounds.scss +2 -34
  238. package/src/styles/base/borders.scss +18 -23
  239. package/src/styles/base/scrolling.scss +97 -29
  240. package/src/styles/base/{shadows.scss → shadow_transitions_hover_refactor.scss} +55 -2
  241. package/src/styles/config.scss +69 -17
  242. package/src/styles/layout.scss +12 -182
  243. package/src/styles/reset.scss +20 -21
  244. package/src/styles/responsive.scss +4 -67
  245. package/src/styles/theme.scss +3 -4
  246. package/src/styles/typography.scss +15 -17
  247. package/src/assets/fonts/AvenirNext-Bold.woff2 +0 -0
  248. package/src/assets/fonts/AvenirNext-DemiBold.woff2 +0 -0
  249. package/src/assets/fonts/AvenirNext-Heavy.woff2 +0 -0
  250. package/src/assets/fonts/AvenirNext-Medium.woff2 +0 -0
  251. package/src/assets/fonts/AvenirNext-Regular.woff2 +0 -0
  252. package/src/assets/fonts/AvenirNext-UltraLight.woff2 +0 -0
  253. package/src/modules/files/middlewares/server/md.js +0 -152
  254. package/src/modules/files/middlewares/server/middlewareMulter.js +0 -121
  255. package/src/modules/organizations/controllers/organizations.new.controller.js +0 -372
  256. package/src/modules/products/components/blocks/EditCategories.vue +0 -68
  257. package/src/modules/products/components/sections/EditParameters.vue +0 -58
  258. package/src/modules/products/components/sections/EditProductImages.vue +0 -67
  259. package/src/modules/spots/components/sections/Feed.vue +0 -64
  260. package/src/styles/base/border-radius.scss +0 -47
  261. package/src/styles/base/cursors.scss +0 -23
  262. package/src/styles/base/height.scss +0 -60
  263. package/src/styles/base/hovers.scss +0 -110
  264. package/src/styles/base/positions.scss +0 -192
  265. package/src/styles/base/transitions.scss +0 -137
  266. package/src/styles/base/width.scss +0 -2
  267. package/src/styles/components/block.scss +0 -18
  268. package/src/styles/components/breadcrumbs.scss +0 -0
  269. package/src/styles/components/input.scss +0 -319
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ const require$$0 = require("jsonwebtoken");
3
+ const require$$0$1 = require("mongodb");
4
+ const jwt = require$$0;
5
+ const middlewareFactory$4 = (db) => {
6
+ const User = db.user;
7
+ const Role = db.role;
8
+ const verifyToken = async (req, res, next) => {
9
+ try {
10
+ console.log(req.cookies);
11
+ let user = JSON.parse(req.cookies.user);
12
+ let token = req.headers["x-access-token"] || user.accessToken;
13
+ if (!token) {
14
+ return res.status(403).send({ message: "No token provided!" });
15
+ }
16
+ const decoded = jwt.verify(token, process.env.SECRET_KEY);
17
+ req.userId = decoded._id;
18
+ console.log("success");
19
+ next();
20
+ } catch (err) {
21
+ console.log(err);
22
+ return res.status(401).send({ message: "Unauthorized!" });
23
+ }
24
+ };
25
+ const checkRole = (roleToCheck) => async (req, res, next) => {
26
+ try {
27
+ const user = await User.findById(req.userId).exec();
28
+ if (!user) {
29
+ return res.status(404).send({ message: "User Not found." });
30
+ }
31
+ const roles = await Role.find({ _id: { $in: user.roles } }).exec();
32
+ for (let role of roles) {
33
+ if (role.name === roleToCheck) {
34
+ next();
35
+ return;
36
+ }
37
+ }
38
+ res.status(403).send({ message: `Require ${roleToCheck} Role!` });
39
+ } catch (err) {
40
+ res.status(500).send({ message: err.message });
41
+ }
42
+ };
43
+ const isAdmin = checkRole("admin");
44
+ const isModerator = checkRole("moderator");
45
+ return {
46
+ verifyToken,
47
+ isAdmin,
48
+ isModerator
49
+ };
50
+ };
51
+ var authJwt = middlewareFactory$4;
52
+ const middlewareFactory$3 = (db) => {
53
+ const User = db.user;
54
+ db.role;
55
+ const checkDuplicateUsernameOrEmail = async (req, res, next) => {
56
+ const { type, email, phone } = req.body;
57
+ let query;
58
+ if (type === "phone" && phone) {
59
+ query = { phone };
60
+ }
61
+ if (type === "email" && email) {
62
+ query = { email };
63
+ }
64
+ try {
65
+ const user = await User.findOne(query).exec();
66
+ if (user) {
67
+ res.status(400).send({ errorCode: "USER_ALREADY_REGISTERED" });
68
+ return;
69
+ }
70
+ next();
71
+ } catch (err) {
72
+ console.log(err);
73
+ res.status(500).send({ message: err.message });
74
+ }
75
+ };
76
+ const checkRolesExisted = (req, res, next) => {
77
+ if (req.body.roles) {
78
+ for (let i = 0; i < req.body.roles.length; i++) {
79
+ if (!ROLES.includes(req.body.roles[i])) {
80
+ res.status(400).send({
81
+ message: `Failed! Role ${req.body.roles[i]} does not exist!`
82
+ });
83
+ return;
84
+ }
85
+ }
86
+ }
87
+ next();
88
+ };
89
+ return {
90
+ checkDuplicateUsernameOrEmail,
91
+ checkRolesExisted
92
+ };
93
+ };
94
+ var verifySignUp = middlewareFactory$3;
95
+ const middlewareFactory$2 = (db) => {
96
+ const User = db.user;
97
+ db.role;
98
+ const checkUserExist = async (req, res, next) => {
99
+ const { type, email, phone } = req.body;
100
+ let query;
101
+ if (type === "phone" && phone) {
102
+ query = { phone };
103
+ }
104
+ if (type === "email" && email) {
105
+ query = { email };
106
+ }
107
+ try {
108
+ const user = await User.findOne(query).exec();
109
+ if (!user) {
110
+ console.log(query);
111
+ res.status(400).send({ errorCode: "USER_NOT_REGISTERED_YET" });
112
+ return;
113
+ }
114
+ next();
115
+ } catch (err) {
116
+ res.status(500).send({ message: err.message });
117
+ }
118
+ };
119
+ return {
120
+ checkUserExist
121
+ };
122
+ };
123
+ var verifyUser = middlewareFactory$2;
124
+ const { ObjectId } = require$$0$1;
125
+ const middlewareFactory$1 = (db) => {
126
+ const User = db.user;
127
+ const Invite = db.invite;
128
+ const Membership = db.membership;
129
+ const checkInviteExist = async (req, res, next) => {
130
+ for (let invite of req.body) {
131
+ let query;
132
+ if (invite.contact.includes("@")) {
133
+ query = { invitedEmail: invite.contact };
134
+ } else {
135
+ query = { invitedPhone: invite.contact };
136
+ }
137
+ query.organization = req.params._id;
138
+ const userInvite = await Invite.findOne(query).exec();
139
+ if (userInvite) {
140
+ console.log(userInvite);
141
+ res.status(400).send({ message: "Инвайт c таким email или телефоном уже создан!" });
142
+ return;
143
+ }
144
+ }
145
+ next();
146
+ };
147
+ const checkUsersExist = async (req, res, next) => {
148
+ for (let invite of req.body) {
149
+ let query;
150
+ if (invite.contact.includes("@")) {
151
+ query = { email: invite.contact };
152
+ } else {
153
+ query = { phone: invite.contact };
154
+ }
155
+ const user = await User.findOne(query).exec();
156
+ console.log(req.params);
157
+ if (user) {
158
+ const membership = await Membership.findOne({ user: new ObjectId(user._id), organization: req.params._id }).exec();
159
+ if (membership) {
160
+ console.log(membership);
161
+ res.status(400).send({ message: "Пользователь с таким email или телефоном уже добавлен в организацию!" });
162
+ return;
163
+ }
164
+ }
165
+ }
166
+ next();
167
+ };
168
+ return {
169
+ checkInviteExist,
170
+ checkUsersExist
171
+ };
172
+ };
173
+ var verifyInvites = middlewareFactory$1;
174
+ const middlewareFactory = (db) => {
175
+ const Category = db.category;
176
+ const checkCategoryExistOrNot = async (req, res, next) => {
177
+ try {
178
+ const category = await Category.findOne({ url: req.body.url });
179
+ if (category) {
180
+ res.status(400).send({ message: "Failed! Category with this URL is already in use!" });
181
+ return;
182
+ }
183
+ next();
184
+ } catch (err) {
185
+ res.status(500).send({ message: err });
186
+ }
187
+ };
188
+ return {
189
+ checkCategoryExistOrNot
190
+ };
191
+ };
192
+ var verifyCategory = middlewareFactory;
193
+ const middlewareIndexFactory = (db) => {
194
+ const authJwt$1 = authJwt(db);
195
+ const verifySignUp$1 = verifySignUp(db);
196
+ const verifyUser$1 = verifyUser(db);
197
+ const verifyInvites$1 = verifyInvites(db);
198
+ const verifyCategory$1 = verifyCategory(db);
199
+ return {
200
+ authJwt: authJwt$1,
201
+ verifySignUp: verifySignUp$1,
202
+ verifyUser: verifyUser$1,
203
+ verifyInvites: verifyInvites$1,
204
+ verifyCategory: verifyCategory$1
205
+ };
206
+ };
207
+ var server = middlewareIndexFactory;
208
+ exports.authJwt = authJwt;
209
+ exports.server = server;
210
+ exports.verifyCategory = verifyCategory;
211
+ exports.verifyInvites = verifyInvites;
212
+ exports.verifySignUp = verifySignUp;
213
+ exports.verifyUser = verifyUser;
@@ -0,0 +1,214 @@
1
+ import require$$0 from "jsonwebtoken";
2
+ import require$$0$1 from "mongodb";
3
+ const jwt = require$$0;
4
+ const middlewareFactory$4 = (db) => {
5
+ const User = db.user;
6
+ const Role = db.role;
7
+ const verifyToken = async (req, res, next) => {
8
+ try {
9
+ console.log(req.cookies);
10
+ let user = JSON.parse(req.cookies.user);
11
+ let token = req.headers["x-access-token"] || user.accessToken;
12
+ if (!token) {
13
+ return res.status(403).send({ message: "No token provided!" });
14
+ }
15
+ const decoded = jwt.verify(token, process.env.SECRET_KEY);
16
+ req.userId = decoded._id;
17
+ console.log("success");
18
+ next();
19
+ } catch (err) {
20
+ console.log(err);
21
+ return res.status(401).send({ message: "Unauthorized!" });
22
+ }
23
+ };
24
+ const checkRole = (roleToCheck) => async (req, res, next) => {
25
+ try {
26
+ const user = await User.findById(req.userId).exec();
27
+ if (!user) {
28
+ return res.status(404).send({ message: "User Not found." });
29
+ }
30
+ const roles = await Role.find({ _id: { $in: user.roles } }).exec();
31
+ for (let role of roles) {
32
+ if (role.name === roleToCheck) {
33
+ next();
34
+ return;
35
+ }
36
+ }
37
+ res.status(403).send({ message: `Require ${roleToCheck} Role!` });
38
+ } catch (err) {
39
+ res.status(500).send({ message: err.message });
40
+ }
41
+ };
42
+ const isAdmin = checkRole("admin");
43
+ const isModerator = checkRole("moderator");
44
+ return {
45
+ verifyToken,
46
+ isAdmin,
47
+ isModerator
48
+ };
49
+ };
50
+ var authJwt = middlewareFactory$4;
51
+ const middlewareFactory$3 = (db) => {
52
+ const User = db.user;
53
+ db.role;
54
+ const checkDuplicateUsernameOrEmail = async (req, res, next) => {
55
+ const { type, email, phone } = req.body;
56
+ let query;
57
+ if (type === "phone" && phone) {
58
+ query = { phone };
59
+ }
60
+ if (type === "email" && email) {
61
+ query = { email };
62
+ }
63
+ try {
64
+ const user = await User.findOne(query).exec();
65
+ if (user) {
66
+ res.status(400).send({ errorCode: "USER_ALREADY_REGISTERED" });
67
+ return;
68
+ }
69
+ next();
70
+ } catch (err) {
71
+ console.log(err);
72
+ res.status(500).send({ message: err.message });
73
+ }
74
+ };
75
+ const checkRolesExisted = (req, res, next) => {
76
+ if (req.body.roles) {
77
+ for (let i = 0; i < req.body.roles.length; i++) {
78
+ if (!ROLES.includes(req.body.roles[i])) {
79
+ res.status(400).send({
80
+ message: `Failed! Role ${req.body.roles[i]} does not exist!`
81
+ });
82
+ return;
83
+ }
84
+ }
85
+ }
86
+ next();
87
+ };
88
+ return {
89
+ checkDuplicateUsernameOrEmail,
90
+ checkRolesExisted
91
+ };
92
+ };
93
+ var verifySignUp = middlewareFactory$3;
94
+ const middlewareFactory$2 = (db) => {
95
+ const User = db.user;
96
+ db.role;
97
+ const checkUserExist = async (req, res, next) => {
98
+ const { type, email, phone } = req.body;
99
+ let query;
100
+ if (type === "phone" && phone) {
101
+ query = { phone };
102
+ }
103
+ if (type === "email" && email) {
104
+ query = { email };
105
+ }
106
+ try {
107
+ const user = await User.findOne(query).exec();
108
+ if (!user) {
109
+ console.log(query);
110
+ res.status(400).send({ errorCode: "USER_NOT_REGISTERED_YET" });
111
+ return;
112
+ }
113
+ next();
114
+ } catch (err) {
115
+ res.status(500).send({ message: err.message });
116
+ }
117
+ };
118
+ return {
119
+ checkUserExist
120
+ };
121
+ };
122
+ var verifyUser = middlewareFactory$2;
123
+ const { ObjectId } = require$$0$1;
124
+ const middlewareFactory$1 = (db) => {
125
+ const User = db.user;
126
+ const Invite = db.invite;
127
+ const Membership = db.membership;
128
+ const checkInviteExist = async (req, res, next) => {
129
+ for (let invite of req.body) {
130
+ let query;
131
+ if (invite.contact.includes("@")) {
132
+ query = { invitedEmail: invite.contact };
133
+ } else {
134
+ query = { invitedPhone: invite.contact };
135
+ }
136
+ query.organization = req.params._id;
137
+ const userInvite = await Invite.findOne(query).exec();
138
+ if (userInvite) {
139
+ console.log(userInvite);
140
+ res.status(400).send({ message: "Инвайт c таким email или телефоном уже создан!" });
141
+ return;
142
+ }
143
+ }
144
+ next();
145
+ };
146
+ const checkUsersExist = async (req, res, next) => {
147
+ for (let invite of req.body) {
148
+ let query;
149
+ if (invite.contact.includes("@")) {
150
+ query = { email: invite.contact };
151
+ } else {
152
+ query = { phone: invite.contact };
153
+ }
154
+ const user = await User.findOne(query).exec();
155
+ console.log(req.params);
156
+ if (user) {
157
+ const membership = await Membership.findOne({ user: new ObjectId(user._id), organization: req.params._id }).exec();
158
+ if (membership) {
159
+ console.log(membership);
160
+ res.status(400).send({ message: "Пользователь с таким email или телефоном уже добавлен в организацию!" });
161
+ return;
162
+ }
163
+ }
164
+ }
165
+ next();
166
+ };
167
+ return {
168
+ checkInviteExist,
169
+ checkUsersExist
170
+ };
171
+ };
172
+ var verifyInvites = middlewareFactory$1;
173
+ const middlewareFactory = (db) => {
174
+ const Category = db.category;
175
+ const checkCategoryExistOrNot = async (req, res, next) => {
176
+ try {
177
+ const category = await Category.findOne({ url: req.body.url });
178
+ if (category) {
179
+ res.status(400).send({ message: "Failed! Category with this URL is already in use!" });
180
+ return;
181
+ }
182
+ next();
183
+ } catch (err) {
184
+ res.status(500).send({ message: err });
185
+ }
186
+ };
187
+ return {
188
+ checkCategoryExistOrNot
189
+ };
190
+ };
191
+ var verifyCategory = middlewareFactory;
192
+ const middlewareIndexFactory = (db) => {
193
+ const authJwt$1 = authJwt(db);
194
+ const verifySignUp$1 = verifySignUp(db);
195
+ const verifyUser$1 = verifyUser(db);
196
+ const verifyInvites$1 = verifyInvites(db);
197
+ const verifyCategory$1 = verifyCategory(db);
198
+ return {
199
+ authJwt: authJwt$1,
200
+ verifySignUp: verifySignUp$1,
201
+ verifyUser: verifyUser$1,
202
+ verifyInvites: verifyInvites$1,
203
+ verifyCategory: verifyCategory$1
204
+ };
205
+ };
206
+ var server = middlewareIndexFactory;
207
+ export {
208
+ verifyInvites as a,
209
+ authJwt as b,
210
+ verifySignUp as c,
211
+ verifyCategory as d,
212
+ server as s,
213
+ verifyUser as v
214
+ };
@@ -0,0 +1,68 @@
1
+ import require$$0 from "dotenv";
2
+ import require$$1 from "nodemailer";
3
+ import require$$2 from "axios";
4
+ require$$0.config();
5
+ const nodemailer = require$$1;
6
+ const axios = require$$2;
7
+ async function sendEmail(to, subject, text) {
8
+ const transporter = nodemailer.createTransport({
9
+ host: process.env.SMTP_HOST,
10
+ port: process.env.SMTP_PORT,
11
+ secure: process.env.SMTP_SECURE,
12
+ auth: {
13
+ user: process.env.SMTP_USER,
14
+ pass: process.env.SMTP_PASSWORD
15
+ }
16
+ });
17
+ const mailOptions = {
18
+ from: `${process.env.SMTP_NAME} <${process.env.SMTP_EMAIL}>`,
19
+ to,
20
+ subject,
21
+ text
22
+ };
23
+ try {
24
+ const info = await transporter.sendMail(mailOptions);
25
+ console.log("Email sent: " + info.response);
26
+ return true;
27
+ } catch (error) {
28
+ console.log(error);
29
+ return false;
30
+ }
31
+ }
32
+ async function sendSms(phone, message) {
33
+ const sessionUrl = `https://api.sms.to/sms/send?api_key=${process.env.SMS_API_KEY}&to=${phone}&message=${encodeURIComponent(message)}&sender_id=${encodeURIComponent(process.env.APP_NAME)}`;
34
+ console.log(`Phone:${phone} message:${message} session: ${sessionUrl}`);
35
+ try {
36
+ const response = await axios.get(sessionUrl);
37
+ console.log("SMS sent");
38
+ return true;
39
+ } catch (error) {
40
+ console.log(error);
41
+ return false;
42
+ }
43
+ }
44
+ async function sendChatMessageTelegram(chatIds, text) {
45
+ const telegramToken = process.env.TELEGRAM_BOT_TOKEN;
46
+ const telegramUrl = `https://api.telegram.org/bot${telegramToken}/sendMessage`;
47
+ try {
48
+ for (const chatId of chatIds) {
49
+ await axios.post(telegramUrl, {
50
+ chat_id: chatId,
51
+ text
52
+ });
53
+ }
54
+ console.log("Telegram message sent");
55
+ return true;
56
+ } catch (error) {
57
+ console.log(error);
58
+ return false;
59
+ }
60
+ }
61
+ var mailing = {
62
+ sendEmail,
63
+ sendSms,
64
+ sendChatMessageTelegram
65
+ };
66
+ export {
67
+ mailing as m
68
+ };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ const require$$0 = require("dotenv");
3
+ const require$$1 = require("nodemailer");
4
+ const require$$2 = require("axios");
5
+ require$$0.config();
6
+ const nodemailer = require$$1;
7
+ const axios = require$$2;
8
+ async function sendEmail(to, subject, text) {
9
+ const transporter = nodemailer.createTransport({
10
+ host: process.env.SMTP_HOST,
11
+ port: process.env.SMTP_PORT,
12
+ secure: process.env.SMTP_SECURE,
13
+ auth: {
14
+ user: process.env.SMTP_USER,
15
+ pass: process.env.SMTP_PASSWORD
16
+ }
17
+ });
18
+ const mailOptions = {
19
+ from: `${process.env.SMTP_NAME} <${process.env.SMTP_EMAIL}>`,
20
+ to,
21
+ subject,
22
+ text
23
+ };
24
+ try {
25
+ const info = await transporter.sendMail(mailOptions);
26
+ console.log("Email sent: " + info.response);
27
+ return true;
28
+ } catch (error) {
29
+ console.log(error);
30
+ return false;
31
+ }
32
+ }
33
+ async function sendSms(phone, message) {
34
+ const sessionUrl = `https://api.sms.to/sms/send?api_key=${process.env.SMS_API_KEY}&to=${phone}&message=${encodeURIComponent(message)}&sender_id=${encodeURIComponent(process.env.APP_NAME)}`;
35
+ console.log(`Phone:${phone} message:${message} session: ${sessionUrl}`);
36
+ try {
37
+ const response = await axios.get(sessionUrl);
38
+ console.log("SMS sent");
39
+ return true;
40
+ } catch (error) {
41
+ console.log(error);
42
+ return false;
43
+ }
44
+ }
45
+ async function sendChatMessageTelegram(chatIds, text) {
46
+ const telegramToken = process.env.TELEGRAM_BOT_TOKEN;
47
+ const telegramUrl = `https://api.telegram.org/bot${telegramToken}/sendMessage`;
48
+ try {
49
+ for (const chatId of chatIds) {
50
+ await axios.post(telegramUrl, {
51
+ chat_id: chatId,
52
+ text
53
+ });
54
+ }
55
+ console.log("Telegram message sent");
56
+ return true;
57
+ } catch (error) {
58
+ console.log(error);
59
+ return false;
60
+ }
61
+ }
62
+ var mailing = {
63
+ sendEmail,
64
+ sendSms,
65
+ sendChatMessageTelegram
66
+ };
67
+ exports.mailing = mailing;