@ozdao/prometheus-framework 0.2.137 → 0.2.139

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. package/dist/auth.server.js +29 -14
  2. package/dist/auth.server.mjs +29 -14
  3. package/dist/community.server.js +3 -3
  4. package/dist/community.server.mjs +3 -3
  5. package/dist/events.server.js +3 -3
  6. package/dist/events.server.mjs +3 -3
  7. package/dist/files.server.js +3 -3
  8. package/dist/files.server.mjs +3 -3
  9. package/dist/gallery.server.js +4 -4
  10. package/dist/gallery.server.mjs +4 -4
  11. package/dist/index-DNI4aUP2.js +259 -0
  12. package/dist/index-Tcyehi73.mjs +260 -0
  13. package/dist/main-DTHFR7H_.mjs +14510 -0
  14. package/dist/main-wXdocsbd.js +92 -0
  15. package/dist/main.css +1 -1
  16. package/dist/orders.server.js +9 -8
  17. package/dist/orders.server.mjs +9 -8
  18. package/dist/organizations.server.js +32 -17
  19. package/dist/organizations.server.mjs +32 -17
  20. package/dist/products.server.js +37 -5
  21. package/dist/products.server.mjs +37 -5
  22. package/dist/prometheus-framework/src/components/Block/Block.vue.cjs +1 -1
  23. package/dist/prometheus-framework/src/components/Block/Block.vue.js +1 -1
  24. package/dist/prometheus-framework/src/components/Completion/Completion.vue.cjs +1 -1
  25. package/dist/prometheus-framework/src/components/Completion/Completion.vue.js +19 -19
  26. package/dist/prometheus-framework/src/components/Feed/Feed.vue.cjs +1 -1
  27. package/dist/prometheus-framework/src/components/Feed/Feed.vue.js +1 -1
  28. package/dist/prometheus-framework/src/components/Map/Map.vue.cjs +1 -1
  29. package/dist/prometheus-framework/src/components/Map/Map.vue.js +3 -2
  30. package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.cjs +1 -1
  31. package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.js +32 -31
  32. package/dist/prometheus-framework/src/modules/auth/store/auth.cjs +1 -1
  33. package/dist/prometheus-framework/src/modules/auth/store/auth.js +50 -47
  34. package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.cjs +1 -1
  35. package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.js +1 -1
  36. package/dist/prometheus-framework/src/modules/community/components/sections/HotPosts.vue.cjs +1 -1
  37. package/dist/prometheus-framework/src/modules/community/components/sections/HotPosts.vue.js +1 -1
  38. package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.cjs +1 -1
  39. package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.js +2 -2
  40. package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.cjs +1 -1
  41. package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.js +1 -1
  42. package/dist/prometheus-framework/src/modules/marketplace/store/marketplace.cjs +1 -1
  43. package/dist/prometheus-framework/src/modules/marketplace/store/marketplace.js +1 -1
  44. package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.cjs +1 -1
  45. package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.js +12 -12
  46. package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.cjs +1 -1
  47. package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.js +2 -2
  48. package/dist/prometheus-framework/src/modules/organizations/components/blocks/CardOrganization.vue.cjs +1 -1
  49. package/dist/prometheus-framework/src/modules/organizations/components/blocks/CardOrganization.vue.js +41 -38
  50. package/dist/prometheus-framework/src/modules/organizations/components/pages/Members.vue.cjs +1 -1
  51. package/dist/prometheus-framework/src/modules/organizations/components/pages/Members.vue.js +123 -114
  52. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.cjs +1 -1
  53. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.js +51 -52
  54. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.cjs +1 -1
  55. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.js +1 -1
  56. package/dist/prometheus-framework/src/modules/organizations/components/sections/DetailsTab.vue.cjs +1 -1
  57. package/dist/prometheus-framework/src/modules/organizations/components/sections/DetailsTab.vue.js +16 -15
  58. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.cjs +1 -1
  59. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.js +120 -60
  60. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.cjs +1 -1
  61. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.js +1 -1
  62. package/dist/prometheus-framework/src/modules/organizations/store/invites.cjs +1 -1
  63. package/dist/prometheus-framework/src/modules/organizations/store/invites.js +25 -24
  64. package/dist/prometheus-framework/src/modules/spots/components/blocks/CardSpot.vue.cjs +1 -1
  65. package/dist/prometheus-framework/src/modules/spots/components/blocks/CardSpot.vue.js +7 -7
  66. package/dist/prometheus-framework/src/modules/spots/components/layouts/Spots.vue.cjs +1 -1
  67. package/dist/prometheus-framework/src/modules/spots/components/layouts/Spots.vue.js +3 -3
  68. package/dist/prometheus-framework/src/modules/spots/components/pages/Map.vue.cjs +1 -1
  69. package/dist/prometheus-framework/src/modules/spots/components/pages/Map.vue.js +65 -66
  70. package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.cjs +1 -1
  71. package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.js +81 -76
  72. package/dist/prometheus-framework/src/modules/spots/router/spots.cjs +1 -1
  73. package/dist/prometheus-framework/src/modules/spots/router/spots.js +1 -1
  74. package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.cjs +1 -1
  75. package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.js +2 -2
  76. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.cjs +1 -1
  77. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.js +78 -74
  78. package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.cjs +1 -1
  79. package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.js +2 -2
  80. package/dist/prometheus-framework.cjs.js +1 -1
  81. package/dist/prometheus-framework.es.js +1 -1
  82. package/dist/reports.server.js +0 -3
  83. package/dist/reports.server.mjs +0 -3
  84. package/dist/spots.server.js +3 -3
  85. package/dist/spots.server.mjs +3 -3
  86. package/dist/style.css +1 -1
  87. package/dist/wallet.server.js +5 -5
  88. package/dist/wallet.server.mjs +8 -8
  89. package/dist/web-Dh669DqQ.mjs +54 -0
  90. package/dist/web-Dt2RCU54.js +1 -0
  91. package/package.json +1 -1
  92. package/src/components/Completion/Completion.vue +29 -30
  93. package/src/components/Map/Map.vue +2 -2
  94. package/src/modules/auth/components/pages/Invite.vue +4 -2
  95. package/src/modules/auth/controllers/auth.controller.js +30 -12
  96. package/src/modules/auth/middlewares/authJwt.js +80 -0
  97. package/src/modules/{middlewares/server → auth/middlewares}/index.js +1 -3
  98. package/src/modules/{middlewares/server → auth/middlewares}/verifyAccesses.js +1 -1
  99. package/src/modules/auth/routes/auth.routes.js +2 -2
  100. package/src/modules/auth/routes/twofa.routes.js +1 -1
  101. package/src/modules/auth/store/auth.js +9 -0
  102. package/src/modules/chats/routes/chats.routes.js +1 -1
  103. package/src/modules/community/routes/blog.routes.js +2 -2
  104. package/src/modules/events/routes/events.routes.js +2 -2
  105. package/src/modules/files/routes/files.routes.js +2 -2
  106. package/src/modules/gallery/routes/gallery.routes.js +4 -5
  107. package/src/modules/globals/services/globals.crud.js +2 -2
  108. package/src/modules/marketplace/store/marketplace.js +1 -1
  109. package/src/modules/orders/components/pages/OrderCreateBackoffice.vue +2 -2
  110. package/src/modules/orders/components/sections/FormAddCustomer.vue +2 -2
  111. package/src/modules/orders/controllers/orders.controller.js +1 -0
  112. package/src/modules/orders/routes/applications.routes.js +2 -2
  113. package/src/modules/orders/routes/orders.routes.js +2 -2
  114. package/src/modules/organizations/components/blocks/CardOrganization.vue +9 -7
  115. package/src/modules/organizations/components/pages/Members.vue +26 -15
  116. package/src/modules/organizations/components/pages/Organization.vue +3 -3
  117. package/src/modules/organizations/components/sections/DetailsTab.vue +1 -1
  118. package/src/modules/organizations/components/sections/MembersAdd.vue +101 -43
  119. package/src/modules/organizations/controllers/invites.controller.js +18 -13
  120. package/src/modules/organizations/controllers/memberships.controller.js +18 -11
  121. package/src/modules/organizations/controllers/organizations.controller.js +3 -4
  122. package/src/modules/organizations/models/membership.model.js +2 -0
  123. package/src/modules/organizations/models/organization.model.js +4 -0
  124. package/src/modules/organizations/routes/invites.routes.js +2 -2
  125. package/src/modules/organizations/store/invites.js +2 -1
  126. package/src/modules/products/controllers/leftovers.controller.js +1 -1
  127. package/src/modules/products/middlewares/index.js +11 -0
  128. package/src/modules/products/routes/categories.routes.js +2 -2
  129. package/src/modules/reports/routes/reports.routes.js +2 -2
  130. package/src/modules/spots/components/blocks/CardSpot.vue +0 -1
  131. package/src/modules/spots/components/layouts/Spots.vue +2 -2
  132. package/src/modules/spots/components/pages/Map.vue +79 -78
  133. package/src/modules/spots/components/pages/SpotEdit.vue +8 -5
  134. package/src/modules/spots/controllers/spots.controller.js +1 -5
  135. package/src/modules/spots/router/spots.js +1 -1
  136. package/src/modules/users/components/pages/ProfileEdit.vue +37 -22
  137. package/src/modules/wallet/controllers/routes/payments.routes.js +2 -2
  138. package/src/modules/wallet/controllers/routes/rewards.routes.js +2 -2
  139. package/src/modules/middlewares/server/authJwt.js +0 -68
  140. /package/src/modules/{middlewares/server → auth/middlewares}/authSecret.js +0 -0
  141. /package/src/modules/{middlewares/server → auth/middlewares}/verifyInvites.js +0 -0
  142. /package/src/modules/{middlewares/server → auth/middlewares}/verifySignUp.js +0 -0
  143. /package/src/modules/{middlewares/server → auth/middlewares}/verifyUser.js +0 -0
  144. /package/src/modules/globals/services/{globals.cashe.js → globals.cache.js} +0 -0
  145. /package/src/modules/{middlewares/server → products/middlewares}/verifyCategory.js +0 -0
@@ -5,7 +5,7 @@ const require$$1$1 = require("bcryptjs");
5
5
  const require$$0$1 = require("mongoose");
6
6
  const require$$1 = require("jwk-to-pem");
7
7
  const mailing = require("./mailing-BX0q8DIs.js");
8
- const index = require("./index-CDbtWkBj.js");
8
+ const index = require("./index-DNI4aUP2.js");
9
9
  const jwt$1 = require$$0;
10
10
  const jwkToPem = require$$1;
11
11
  async function verifyAppleIdToken$1(id_token) {
@@ -228,16 +228,13 @@ const controllerFactory$3 = (db) => {
228
228
  const ownedOrgs = await Organization.find({ owner: uid });
229
229
  const ownedOrgIds = ownedOrgs.map((org) => org._id.toString());
230
230
  const accesses = {};
231
- const processAccesses = (orgId, isOwner) => {
231
+ const processAccesses = (orgId, isOwner, deptAccesses) => {
232
232
  if (!accesses[orgId]) {
233
- accesses[orgId] = {
234
- organization: orgId,
235
- rights: {}
236
- };
233
+ accesses[orgId] = { organization: orgId, rights: {} };
237
234
  }
238
235
  const rights = accesses[orgId].rights;
239
- const defaultAccesses = new Department();
240
- const accessData = isOwner ? defaultAccesses.accesses : (depts.find((dept) => dept.organization.toString() === orgId) || {}).accesses;
236
+ const defaultAccesses = new Department().accesses;
237
+ const accessData = isOwner ? defaultAccesses : deptAccesses;
241
238
  Object.keys(accessData).forEach((key) => {
242
239
  if (!rights[key]) {
243
240
  rights[key] = {};
@@ -248,12 +245,30 @@ const controllerFactory$3 = (db) => {
248
245
  });
249
246
  });
250
247
  };
251
- depts.forEach((dept) => {
248
+ const orgDepts = depts.reduce((acc, dept) => {
252
249
  const orgId = dept.organization.toString();
253
- processAccesses(orgId, false);
250
+ if (!acc[orgId]) {
251
+ acc[orgId] = [];
252
+ }
253
+ acc[orgId].push(dept);
254
+ return acc;
255
+ }, {});
256
+ Object.entries(orgDepts).forEach(([orgId, departments]) => {
257
+ const combinedAccesses = departments.reduce((acc, dept) => {
258
+ Object.entries(dept.accesses).forEach(([key, rights]) => {
259
+ if (!acc[key]) {
260
+ acc[key] = {};
261
+ }
262
+ Object.entries(rights).forEach(([right, value]) => {
263
+ acc[key][right] = acc[key][right] || value;
264
+ });
265
+ });
266
+ return acc;
267
+ }, {});
268
+ processAccesses(orgId, false, combinedAccesses);
254
269
  });
255
270
  ownedOrgIds.forEach((orgId) => {
256
- processAccesses(orgId, true);
271
+ processAccesses(orgId, true, {});
257
272
  });
258
273
  const accessArray = Object.values(accesses);
259
274
  res.status(200).json(accessArray);
@@ -301,7 +316,7 @@ const controllerFactory$2 = (db) => {
301
316
  var twofa_controller = controllerFactory$2;
302
317
  const controllerFactory$1 = auth_controller;
303
318
  const controllerFactoryTwofa = twofa_controller;
304
- const middlewareFactory$1 = index.server;
319
+ const middlewareFactory$1 = index.middlewares;
305
320
  var auth_routes = function(app, db, origins) {
306
321
  const controller = controllerFactory$1(db);
307
322
  const controllerTwofa = controllerFactoryTwofa();
@@ -332,13 +347,13 @@ var auth_routes = function(app, db, origins) {
332
347
  app.get(
333
348
  "/api/auth/check-accesses",
334
349
  [
335
- authJwt.verifyToken
350
+ authJwt.verifyToken(true)
336
351
  ],
337
352
  controller.checkAccesses
338
353
  );
339
354
  };
340
355
  const controllerFactory = twofa_controller;
341
- const middlewareFactory = index.server;
356
+ const middlewareFactory = index.middlewares;
342
357
  var twofa_routes = function(app, db) {
343
358
  const controller = controllerFactory();
344
359
  const { verifySignUp, verifyUser } = middlewareFactory(db);
@@ -4,7 +4,7 @@ import require$$1$1 from "bcryptjs";
4
4
  import require$$0$1 from "mongoose";
5
5
  import require$$1 from "jwk-to-pem";
6
6
  import { m as mailing } from "./mailing-Cdp8NXhP.mjs";
7
- import { s as server } from "./index-C-8xOJnM.mjs";
7
+ import { m as middlewares } from "./index-Tcyehi73.mjs";
8
8
  const jwt$1 = require$$0;
9
9
  const jwkToPem = require$$1;
10
10
  async function verifyAppleIdToken$1(id_token) {
@@ -227,16 +227,13 @@ const controllerFactory$3 = (db) => {
227
227
  const ownedOrgs = await Organization.find({ owner: uid });
228
228
  const ownedOrgIds = ownedOrgs.map((org) => org._id.toString());
229
229
  const accesses = {};
230
- const processAccesses = (orgId, isOwner) => {
230
+ const processAccesses = (orgId, isOwner, deptAccesses) => {
231
231
  if (!accesses[orgId]) {
232
- accesses[orgId] = {
233
- organization: orgId,
234
- rights: {}
235
- };
232
+ accesses[orgId] = { organization: orgId, rights: {} };
236
233
  }
237
234
  const rights = accesses[orgId].rights;
238
- const defaultAccesses = new Department();
239
- const accessData = isOwner ? defaultAccesses.accesses : (depts.find((dept) => dept.organization.toString() === orgId) || {}).accesses;
235
+ const defaultAccesses = new Department().accesses;
236
+ const accessData = isOwner ? defaultAccesses : deptAccesses;
240
237
  Object.keys(accessData).forEach((key) => {
241
238
  if (!rights[key]) {
242
239
  rights[key] = {};
@@ -247,12 +244,30 @@ const controllerFactory$3 = (db) => {
247
244
  });
248
245
  });
249
246
  };
250
- depts.forEach((dept) => {
247
+ const orgDepts = depts.reduce((acc, dept) => {
251
248
  const orgId = dept.organization.toString();
252
- processAccesses(orgId, false);
249
+ if (!acc[orgId]) {
250
+ acc[orgId] = [];
251
+ }
252
+ acc[orgId].push(dept);
253
+ return acc;
254
+ }, {});
255
+ Object.entries(orgDepts).forEach(([orgId, departments]) => {
256
+ const combinedAccesses = departments.reduce((acc, dept) => {
257
+ Object.entries(dept.accesses).forEach(([key, rights]) => {
258
+ if (!acc[key]) {
259
+ acc[key] = {};
260
+ }
261
+ Object.entries(rights).forEach(([right, value]) => {
262
+ acc[key][right] = acc[key][right] || value;
263
+ });
264
+ });
265
+ return acc;
266
+ }, {});
267
+ processAccesses(orgId, false, combinedAccesses);
253
268
  });
254
269
  ownedOrgIds.forEach((orgId) => {
255
- processAccesses(orgId, true);
270
+ processAccesses(orgId, true, {});
256
271
  });
257
272
  const accessArray = Object.values(accesses);
258
273
  res.status(200).json(accessArray);
@@ -300,7 +315,7 @@ const controllerFactory$2 = (db) => {
300
315
  var twofa_controller = controllerFactory$2;
301
316
  const controllerFactory$1 = auth_controller;
302
317
  const controllerFactoryTwofa = twofa_controller;
303
- const middlewareFactory$1 = server;
318
+ const middlewareFactory$1 = middlewares;
304
319
  var auth_routes = function(app, db, origins) {
305
320
  const controller = controllerFactory$1(db);
306
321
  const controllerTwofa = controllerFactoryTwofa();
@@ -331,13 +346,13 @@ var auth_routes = function(app, db, origins) {
331
346
  app.get(
332
347
  "/api/auth/check-accesses",
333
348
  [
334
- authJwt.verifyToken
349
+ authJwt.verifyToken(true)
335
350
  ],
336
351
  controller.checkAccesses
337
352
  );
338
353
  };
339
354
  const controllerFactory = twofa_controller;
340
- const middlewareFactory = server;
355
+ const middlewareFactory = middlewares;
341
356
  var twofa_routes = function(app, db) {
342
357
  const controller = controllerFactory();
343
358
  const { verifySignUp, verifyUser } = middlewareFactory(db);
@@ -4,7 +4,7 @@ const require$$0 = require("mongoose");
4
4
  const queryProcessor$3 = require("./queryProcessor-iewDZq_f.js");
5
5
  require("util");
6
6
  require("uuid");
7
- const index = require("./index-CDbtWkBj.js");
7
+ const index = require("./index-DNI4aUP2.js");
8
8
  const common_schema = require("./common.schema-BFhpUXUt.js");
9
9
  const engagement_schema = require("./engagement.schema-D-9md46B.js");
10
10
  const ownership_schema = require("./ownership.schema-DN0SlQL6.js");
@@ -651,11 +651,11 @@ const middlewareIndexFactory = (db) => {
651
651
  };
652
652
  var server = middlewareIndexFactory;
653
653
  const controllerFactory$2 = blog_controller;
654
- const middlewareFactoryGlobal = index.server;
654
+ const middlewareFactoryAuth = index.middlewares;
655
655
  const middlewareFactoryCommunity = server;
656
656
  var blog_routes = function(app, db, origins) {
657
657
  const controller = controllerFactory$2(db);
658
- middlewareFactoryGlobal(db);
658
+ middlewareFactoryAuth(db);
659
659
  const { verifyBlogpost: verifyBlogpost2 } = middlewareFactoryCommunity(db);
660
660
  app.get(
661
661
  "/api/blog/read",
@@ -3,7 +3,7 @@ import require$$0 from "mongoose";
3
3
  import { q as queryProcessor$3 } from "./queryProcessor-DQSFR9YA.mjs";
4
4
  import "util";
5
5
  import "uuid";
6
- import { s as server$1 } from "./index-C-8xOJnM.mjs";
6
+ import { m as middlewares } from "./index-Tcyehi73.mjs";
7
7
  import { c as common_schema } from "./common.schema-ChBVARrs.mjs";
8
8
  import { e as engagement_schema } from "./engagement.schema-CCdSLKd4.mjs";
9
9
  import { o as ownership_schema } from "./ownership.schema-oyx6eNkZ.mjs";
@@ -650,11 +650,11 @@ const middlewareIndexFactory = (db) => {
650
650
  };
651
651
  var server = middlewareIndexFactory;
652
652
  const controllerFactory$2 = blog_controller;
653
- const middlewareFactoryGlobal = server$1;
653
+ const middlewareFactoryAuth = middlewares;
654
654
  const middlewareFactoryCommunity = server;
655
655
  var blog_routes = function(app, db, origins) {
656
656
  const controller = controllerFactory$2(db);
657
- middlewareFactoryGlobal(db);
657
+ middlewareFactoryAuth(db);
658
658
  const { verifyBlogpost: verifyBlogpost2 } = middlewareFactoryCommunity(db);
659
659
  app.get(
660
660
  "/api/blog/read",
@@ -5,7 +5,7 @@ const require$$0 = require("mongoose");
5
5
  const queryProcessor$2 = require("./queryProcessor-iewDZq_f.js");
6
6
  const metadata_schema = require("./metadata.schema-6slGhpQS.js");
7
7
  const require$$1 = require("stripe");
8
- const index = require("./index-CDbtWkBj.js");
8
+ const index = require("./index-DNI4aUP2.js");
9
9
  const tickets_controller = require("./tickets.controller-WaQ4qMpv.js");
10
10
  const common_schema = require("./common.schema-BFhpUXUt.js");
11
11
  const engagement_schema = require("./engagement.schema-D-9md46B.js");
@@ -641,11 +641,11 @@ const middlewareIndexFactory = (db) => {
641
641
  };
642
642
  var server = middlewareIndexFactory;
643
643
  const controllerFactory$1 = events_controller;
644
- const middlewareFactoryGlobal = index.server;
644
+ const middlewareFactoryAuth = index.middlewares;
645
645
  const middlewareFactoryEvents = server;
646
646
  var events_routes = function(app, db, origins) {
647
647
  const controller = controllerFactory$1(db);
648
- middlewareFactoryGlobal(db);
648
+ middlewareFactoryAuth(db);
649
649
  const { verifyEvent: verifyEvent2 } = middlewareFactoryEvents(db);
650
650
  app.get(
651
651
  "/api/events/read",
@@ -3,7 +3,7 @@ import require$$0 from "mongoose";
3
3
  import { q as queryProcessor$2 } from "./queryProcessor-DQSFR9YA.mjs";
4
4
  import { s as seoFriendlyUrl, m as metadata_schema } from "./metadata.schema-CK5e2O3f.mjs";
5
5
  import require$$1 from "stripe";
6
- import { s as server$1 } from "./index-C-8xOJnM.mjs";
6
+ import { m as middlewares } from "./index-Tcyehi73.mjs";
7
7
  import { t as tickets_controller } from "./tickets.controller-ByZ33N6_.mjs";
8
8
  import { c as common_schema } from "./common.schema-ChBVARrs.mjs";
9
9
  import { e as engagement_schema } from "./engagement.schema-CCdSLKd4.mjs";
@@ -639,11 +639,11 @@ const middlewareIndexFactory = (db) => {
639
639
  };
640
640
  var server = middlewareIndexFactory;
641
641
  const controllerFactory$1 = events_controller;
642
- const middlewareFactoryGlobal = server$1;
642
+ const middlewareFactoryAuth = middlewares;
643
643
  const middlewareFactoryEvents = server;
644
644
  var events_routes = function(app, db, origins) {
645
645
  const controller = controllerFactory$1(db);
646
- middlewareFactoryGlobal(db);
646
+ middlewareFactoryAuth(db);
647
647
  const { verifyEvent: verifyEvent2 } = middlewareFactoryEvents(db);
648
648
  app.get(
649
649
  "/api/events/read",
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const _commonjsHelpers = require("./_commonjsHelpers-DHfMLFPC.js");
3
3
  const require$$0 = require("path");
4
- const index = require("./index-CDbtWkBj.js");
4
+ const index = require("./index-DNI4aUP2.js");
5
5
  const require$$0$1 = require("sharp");
6
6
  const require$$1 = require("fs");
7
7
  const require$$2 = require("fs/promises");
@@ -250,11 +250,11 @@ const middlewareIndexFactory = (db, publicPath) => {
250
250
  };
251
251
  var server = middlewareIndexFactory;
252
252
  const controllerFactory = files_controller;
253
- const middlewareFactoryGlobal = index.server;
253
+ const middlewareFactoryAuth = index.middlewares;
254
254
  const middlewareFactoryFiles = server;
255
255
  var files_routes = function(app, db, origins, publicPath) {
256
256
  const controller = controllerFactory();
257
- middlewareFactoryGlobal(db);
257
+ middlewareFactoryAuth(db);
258
258
  const { middlewareBusboy: middlewareBusboy2 } = middlewareFactoryFiles(db, publicPath);
259
259
  app.post(
260
260
  "/api/upload/image",
@@ -1,6 +1,6 @@
1
1
  import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-CUmg6egw.mjs";
2
2
  import require$$0 from "path";
3
- import { s as server$1 } from "./index-C-8xOJnM.mjs";
3
+ import { m as middlewares } from "./index-Tcyehi73.mjs";
4
4
  import require$$0$1 from "sharp";
5
5
  import require$$1 from "fs";
6
6
  import require$$2 from "fs/promises";
@@ -249,11 +249,11 @@ const middlewareIndexFactory = (db, publicPath) => {
249
249
  };
250
250
  var server = middlewareIndexFactory;
251
251
  const controllerFactory = files_controller;
252
- const middlewareFactoryGlobal = server$1;
252
+ const middlewareFactoryAuth = middlewares;
253
253
  const middlewareFactoryFiles = server;
254
254
  var files_routes = function(app, db, origins, publicPath) {
255
255
  const controller = controllerFactory();
256
- middlewareFactoryGlobal(db);
256
+ middlewareFactoryAuth(db);
257
257
  const { middlewareBusboy: middlewareBusboy2 } = middlewareFactoryFiles(db, publicPath);
258
258
  app.post(
259
259
  "/api/upload/image",
@@ -2,7 +2,7 @@
2
2
  const _commonjsHelpers = require("./_commonjsHelpers-DHfMLFPC.js");
3
3
  const require$$0 = require("path");
4
4
  const queryProcessor = require("./queryProcessor-iewDZq_f.js");
5
- const index = require("./index-CDbtWkBj.js");
5
+ const index = require("./index-DNI4aUP2.js");
6
6
  const common_schema = require("./common.schema-BFhpUXUt.js");
7
7
  const engagement_schema = require("./engagement.schema-D-9md46B.js");
8
8
  const ownership_schema = require("./ownership.schema-DN0SlQL6.js");
@@ -167,16 +167,16 @@ const middlewareFactory = (db) => {
167
167
  };
168
168
  var verifyAccesses = middlewareFactory;
169
169
  const controllerFactory = gallery_controller;
170
- const middlewareFactoryGlobal = index.server;
170
+ const middlewareFactoryAuth = index.middlewares;
171
171
  const middlewareFactoryAccesses = verifyAccesses;
172
172
  var gallery_routes = function(app, db, origins) {
173
173
  const controller = controllerFactory(db);
174
- const { authJwt } = middlewareFactoryGlobal(db);
174
+ const { authJwt } = middlewareFactoryAuth(db);
175
175
  const { verifyRead } = middlewareFactoryAccesses(db);
176
176
  app.get(
177
177
  "/api/gallery/read",
178
178
  [
179
- authJwt.verifyToken,
179
+ authJwt.verifyToken(true),
180
180
  verifyRead("gallery")
181
181
  ],
182
182
  controller.read
@@ -1,7 +1,7 @@
1
1
  import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-CUmg6egw.mjs";
2
2
  import require$$0 from "path";
3
3
  import { q as queryProcessor } from "./queryProcessor-DQSFR9YA.mjs";
4
- import { s as server } from "./index-C-8xOJnM.mjs";
4
+ import { m as middlewares } from "./index-Tcyehi73.mjs";
5
5
  import { c as common_schema } from "./common.schema-ChBVARrs.mjs";
6
6
  import { e as engagement_schema } from "./engagement.schema-CCdSLKd4.mjs";
7
7
  import { o as ownership_schema } from "./ownership.schema-oyx6eNkZ.mjs";
@@ -166,16 +166,16 @@ const middlewareFactory = (db) => {
166
166
  };
167
167
  var verifyAccesses = middlewareFactory;
168
168
  const controllerFactory = gallery_controller;
169
- const middlewareFactoryGlobal = server;
169
+ const middlewareFactoryAuth = middlewares;
170
170
  const middlewareFactoryAccesses = verifyAccesses;
171
171
  var gallery_routes = function(app, db, origins) {
172
172
  const controller = controllerFactory(db);
173
- const { authJwt } = middlewareFactoryGlobal(db);
173
+ const { authJwt } = middlewareFactoryAuth(db);
174
174
  const { verifyRead } = middlewareFactoryAccesses(db);
175
175
  app.get(
176
176
  "/api/gallery/read",
177
177
  [
178
- authJwt.verifyToken,
178
+ authJwt.verifyToken(true),
179
179
  verifyRead("gallery")
180
180
  ],
181
181
  controller.read
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ const require$$0 = require("jsonwebtoken");
3
+ const require$$0$1 = require("crypto");
4
+ const require$$0$2 = require("mongodb");
5
+ var authJwt;
6
+ var hasRequiredAuthJwt;
7
+ function requireAuthJwt() {
8
+ if (hasRequiredAuthJwt) return authJwt;
9
+ hasRequiredAuthJwt = 1;
10
+ const jwt = require$$0;
11
+ const middlewareFactory = (db) => {
12
+ const User = db.user;
13
+ const Role = db.role;
14
+ const verifyToken = (continueOnFail = false) => {
15
+ return async (req, res, next) => {
16
+ try {
17
+ if (!req.cookies.user) {
18
+ req.userId = null;
19
+ if (continueOnFail) {
20
+ return next();
21
+ } else {
22
+ return res.status(401).send({ message: "Unauthorized: No user cookie" });
23
+ }
24
+ }
25
+ let user = JSON.parse(req.cookies.user);
26
+ let token = req.headers["x-access-token"] || user.accessToken;
27
+ if (!token) {
28
+ req.userId = null;
29
+ if (continueOnFail) {
30
+ return next();
31
+ } else {
32
+ return res.status(401).send({ message: "Unauthorized: No token provided" });
33
+ }
34
+ }
35
+ const decoded = jwt.verify(token, process.env.SECRET_KEY);
36
+ req.userId = decoded._id;
37
+ next();
38
+ } catch (err) {
39
+ console.log(err);
40
+ req.userId = null;
41
+ if (continueOnFail) {
42
+ next();
43
+ } else {
44
+ res.status(401).send({ message: "Unauthorized: Invalid token" });
45
+ }
46
+ }
47
+ };
48
+ };
49
+ const checkRole = (roleToCheck) => async (req, res, next) => {
50
+ try {
51
+ const user = await User.findById(req.userId).exec();
52
+ if (!user) {
53
+ return res.status(404).send({ message: "User Not found." });
54
+ }
55
+ const roles = await Role.find({ _id: { $in: user.roles } }).exec();
56
+ for (let role of roles) {
57
+ if (role.name === roleToCheck) {
58
+ next();
59
+ return;
60
+ }
61
+ }
62
+ res.status(403).send({ message: `Require ${roleToCheck} Role!` });
63
+ } catch (err) {
64
+ res.status(500).send({ message: err.message });
65
+ }
66
+ };
67
+ const isAdmin = checkRole("admin");
68
+ const isModerator = checkRole("moderator");
69
+ return {
70
+ verifyToken,
71
+ isAdmin,
72
+ isModerator
73
+ };
74
+ };
75
+ authJwt = middlewareFactory;
76
+ return authJwt;
77
+ }
78
+ var authSecret;
79
+ var hasRequiredAuthSecret;
80
+ function requireAuthSecret() {
81
+ if (hasRequiredAuthSecret) return authSecret;
82
+ hasRequiredAuthSecret = 1;
83
+ const crypto = require$$0$1;
84
+ const middlewareFactory = () => {
85
+ const verifySecret = (method, endpoint, secret) => async (req, res, next) => {
86
+ const requestSignature = req.headers.signature;
87
+ const signature = crypto.createHmac("sha256", secret).update(method + endpoint).digest("hex");
88
+ if (signature === requestSignature) {
89
+ return next();
90
+ }
91
+ res.status(403).send("Forbidden");
92
+ };
93
+ return { verifySecret };
94
+ };
95
+ authSecret = middlewareFactory;
96
+ return authSecret;
97
+ }
98
+ var verifySignUp;
99
+ var hasRequiredVerifySignUp;
100
+ function requireVerifySignUp() {
101
+ if (hasRequiredVerifySignUp) return verifySignUp;
102
+ hasRequiredVerifySignUp = 1;
103
+ const middlewareFactory = (db) => {
104
+ const User = db.user;
105
+ db.role;
106
+ const checkDuplicateUsernameOrEmail = async (req, res, next) => {
107
+ const { type, email, phone } = req.body;
108
+ console.log(req.body);
109
+ let query;
110
+ if (type === "phone" && phone) {
111
+ query = { phone };
112
+ }
113
+ if (type === "email" && email) {
114
+ query = { email };
115
+ }
116
+ try {
117
+ const user = await User.findOne(query).exec();
118
+ if (user) {
119
+ console.log(`USER_ALREADY_REGISTERED`);
120
+ res.status(400).send({ errorCode: "USER_ALREADY_REGISTERED" });
121
+ return;
122
+ }
123
+ next();
124
+ } catch (err) {
125
+ console.log(err);
126
+ res.status(500).send({ message: err.message });
127
+ }
128
+ };
129
+ const checkRolesExisted = (req, res, next) => {
130
+ if (req.body.roles) {
131
+ for (let i = 0; i < req.body.roles.length; i++) {
132
+ if (!ROLES.includes(req.body.roles[i])) {
133
+ console.log(`Failed! Role ${req.body.roles[i]} does not exist!`);
134
+ res.status(400).send({
135
+ message: `Failed! Role ${req.body.roles[i]} does not exist!`
136
+ });
137
+ return;
138
+ }
139
+ }
140
+ }
141
+ next();
142
+ };
143
+ return {
144
+ checkDuplicateUsernameOrEmail,
145
+ checkRolesExisted
146
+ };
147
+ };
148
+ verifySignUp = middlewareFactory;
149
+ return verifySignUp;
150
+ }
151
+ var verifyUser;
152
+ var hasRequiredVerifyUser;
153
+ function requireVerifyUser() {
154
+ if (hasRequiredVerifyUser) return verifyUser;
155
+ hasRequiredVerifyUser = 1;
156
+ const middlewareFactory = (db) => {
157
+ const User = db.user;
158
+ db.role;
159
+ const checkUserExist = async (req, res, next) => {
160
+ const { type, email, phone } = req.body;
161
+ let query;
162
+ if (type === "phone" && phone) {
163
+ query = { phone };
164
+ }
165
+ if (type === "email" && email) {
166
+ query = { email };
167
+ }
168
+ try {
169
+ const user = await User.findOne(query).exec();
170
+ if (!user) {
171
+ console.log(query);
172
+ res.status(400).send({ errorCode: "USER_NOT_REGISTERED_YET" });
173
+ return;
174
+ }
175
+ next();
176
+ } catch (err) {
177
+ res.status(500).send({ message: err.message });
178
+ }
179
+ };
180
+ return {
181
+ checkUserExist
182
+ };
183
+ };
184
+ verifyUser = middlewareFactory;
185
+ return verifyUser;
186
+ }
187
+ var verifyInvites;
188
+ var hasRequiredVerifyInvites;
189
+ function requireVerifyInvites() {
190
+ if (hasRequiredVerifyInvites) return verifyInvites;
191
+ hasRequiredVerifyInvites = 1;
192
+ const { ObjectId } = require$$0$2;
193
+ const middlewareFactory = (db) => {
194
+ const User = db.user;
195
+ const Invite = db.invite;
196
+ const Membership = db.membership;
197
+ const checkInviteExist = async (req, res, next) => {
198
+ for (let invite of req.body.invites) {
199
+ let query;
200
+ if (invite.contact.includes("@")) {
201
+ query = { invitedEmail: invite.contact };
202
+ } else {
203
+ query = { invitedPhone: invite.contact };
204
+ }
205
+ query["owner.target"] = req.body.owner.target;
206
+ const userInvite = await Invite.findOne(query).exec();
207
+ if (userInvite) {
208
+ console.log(userInvite);
209
+ res.status(400).send({ message: "Инвайт c таким email или телефоном уже создан!" });
210
+ return;
211
+ }
212
+ }
213
+ next();
214
+ };
215
+ const checkUsersExist = async (req, res, next) => {
216
+ for (let invite of req.body.invites) {
217
+ let query;
218
+ if (invite.contact.includes("@")) {
219
+ query = { email: invite.contact };
220
+ } else {
221
+ query = { phone: invite.contact };
222
+ }
223
+ const user = await User.findOne(query).exec();
224
+ console.log(req.params);
225
+ if (user) {
226
+ const membership = await Membership.findOne({ user: new ObjectId(user._id), "owner.target": req.body.owner.target }).exec();
227
+ if (membership) {
228
+ console.log(membership);
229
+ res.status(400).send({ message: "Пользователь с таким email или телефоном уже добавлен в организацию!" });
230
+ return;
231
+ }
232
+ }
233
+ }
234
+ next();
235
+ };
236
+ return {
237
+ checkInviteExist,
238
+ checkUsersExist
239
+ };
240
+ };
241
+ verifyInvites = middlewareFactory;
242
+ return verifyInvites;
243
+ }
244
+ const middlewareIndexFactory = (db) => {
245
+ const authJwt2 = requireAuthJwt()(db);
246
+ const authSecret2 = requireAuthSecret()();
247
+ const verifySignUp2 = requireVerifySignUp()(db);
248
+ const verifyUser2 = requireVerifyUser()(db);
249
+ const verifyInvites2 = requireVerifyInvites()(db);
250
+ return {
251
+ authJwt: authJwt2,
252
+ authSecret: authSecret2,
253
+ verifySignUp: verifySignUp2,
254
+ verifyUser: verifyUser2,
255
+ verifyInvites: verifyInvites2
256
+ };
257
+ };
258
+ var middlewares = middlewareIndexFactory;
259
+ exports.middlewares = middlewares;