@ozdao/martyrs 0.2.458 → 0.2.460

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 (139) hide show
  1. package/dist/{Media-Df1hO2ZT.mjs → Media-BKlUty0j.mjs} +1 -1
  2. package/dist/{Media-B9V7fmz-.js → Media-ChTgw58S.js} +1 -1
  3. package/dist/chats.server.js +11 -18
  4. package/dist/chats.server.mjs +11 -18
  5. package/dist/globals.server.js +104 -1
  6. package/dist/globals.server.mjs +104 -1
  7. package/dist/{main-DviXUDiB.js → main-DIXWgUWx.js} +2 -2
  8. package/dist/{main-DbrX42CV.mjs → main-Q8Dr1-HT.mjs} +2 -2
  9. package/dist/martyrs/src/components/EditImages/EditImages.vue.cjs +93 -0
  10. package/dist/martyrs/src/components/EditImages/EditImages.vue.cjs.map +1 -1
  11. package/dist/martyrs/src/components/EditImages/EditImages.vue.js +94 -1
  12. package/dist/martyrs/src/components/EditImages/EditImages.vue.js.map +1 -1
  13. package/dist/martyrs/src/components/EditImages/EditImages.vue2.cjs +0 -93
  14. package/dist/martyrs/src/components/EditImages/EditImages.vue2.cjs.map +1 -1
  15. package/dist/martyrs/src/components/EditImages/EditImages.vue2.js +1 -94
  16. package/dist/martyrs/src/components/EditImages/EditImages.vue2.js.map +1 -1
  17. package/dist/martyrs/src/components/Feed/Feed.vue.cjs +1 -1
  18. package/dist/martyrs/src/components/Feed/Feed.vue.cjs.map +1 -1
  19. package/dist/martyrs/src/components/Feed/Feed.vue.js +1 -1
  20. package/dist/martyrs/src/components/Feed/Feed.vue.js.map +1 -1
  21. package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.cjs → SelectMulti.vue.cjs} +2 -2
  22. package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.js.map → SelectMulti.vue.cjs.map} +1 -1
  23. package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.js → SelectMulti.vue.js} +2 -2
  24. package/dist/martyrs/src/components/SelectMulti/SelectMulti.vue.js.map +1 -0
  25. package/dist/martyrs/src/modules/backoffice/components/partials/Sidebar.vue.cjs +1 -1
  26. package/dist/martyrs/src/modules/backoffice/components/partials/Sidebar.vue.js +1 -1
  27. package/dist/martyrs/src/modules/chats/components/sections/ChatWindow.vue.cjs +1 -0
  28. package/dist/martyrs/src/modules/chats/components/sections/ChatWindow.vue.cjs.map +1 -1
  29. package/dist/martyrs/src/modules/chats/components/sections/ChatWindow.vue.js +1 -0
  30. package/dist/martyrs/src/modules/chats/components/sections/ChatWindow.vue.js.map +1 -1
  31. package/dist/martyrs/src/modules/chats/store/chat.store.cjs +1 -1
  32. package/dist/martyrs/src/modules/chats/store/chat.store.cjs.map +1 -1
  33. package/dist/martyrs/src/modules/chats/store/chat.store.js +1 -1
  34. package/dist/martyrs/src/modules/chats/store/chat.store.js.map +1 -1
  35. package/dist/martyrs/src/modules/community/components/layouts/Community.vue.cjs +2 -2
  36. package/dist/martyrs/src/modules/community/components/layouts/Community.vue.cjs.map +1 -1
  37. package/dist/martyrs/src/modules/community/components/layouts/Community.vue.js +2 -2
  38. package/dist/martyrs/src/modules/community/components/layouts/Community.vue.js.map +1 -1
  39. package/dist/martyrs/src/modules/community/components/sections/Comment.vue.cjs +1 -1
  40. package/dist/martyrs/src/modules/community/components/sections/Comment.vue.cjs.map +1 -1
  41. package/dist/martyrs/src/modules/community/components/sections/Comment.vue.js +1 -1
  42. package/dist/martyrs/src/modules/community/components/sections/Comment.vue.js.map +1 -1
  43. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.cjs +2 -2
  44. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.js +2 -2
  45. package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +2 -2
  46. package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.js +2 -2
  47. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.cjs +1 -1
  48. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.cjs.map +1 -1
  49. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.js +1 -1
  50. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.js.map +1 -1
  51. package/dist/martyrs/src/modules/globals/views/components/partials/Navigation.vue.cjs +45 -37
  52. package/dist/martyrs/src/modules/globals/views/components/partials/Navigation.vue.cjs.map +1 -1
  53. package/dist/martyrs/src/modules/globals/views/components/partials/Navigation.vue.js +46 -38
  54. package/dist/martyrs/src/modules/globals/views/components/partials/Navigation.vue.js.map +1 -1
  55. package/dist/martyrs/src/modules/globals/views/components/partials/Sidebar.vue.cjs +8 -7
  56. package/dist/martyrs/src/modules/globals/views/components/partials/Sidebar.vue.cjs.map +1 -1
  57. package/dist/martyrs/src/modules/globals/views/components/partials/Sidebar.vue.js +8 -7
  58. package/dist/martyrs/src/modules/globals/views/components/partials/Sidebar.vue.js.map +1 -1
  59. package/dist/martyrs/src/modules/globals/views/plugins/AlertDialog.vue.cjs +1 -1
  60. package/dist/martyrs/src/modules/globals/views/plugins/AlertDialog.vue.cjs.map +1 -1
  61. package/dist/martyrs/src/modules/globals/views/plugins/AlertDialog.vue.js +1 -1
  62. package/dist/martyrs/src/modules/globals/views/plugins/AlertDialog.vue.js.map +1 -1
  63. package/dist/martyrs/src/modules/icons/entities/IconTime.vue.cjs +4 -3
  64. package/dist/martyrs/src/modules/icons/entities/IconTime.vue.cjs.map +1 -1
  65. package/dist/martyrs/src/modules/icons/entities/IconTime.vue.js +5 -4
  66. package/dist/martyrs/src/modules/icons/entities/IconTime.vue.js.map +1 -1
  67. package/dist/martyrs/src/modules/notifications/notifications.client.cjs +2 -61
  68. package/dist/martyrs/src/modules/notifications/notifications.client.cjs.map +1 -1
  69. package/dist/martyrs/src/modules/notifications/notifications.client.js +2 -61
  70. package/dist/martyrs/src/modules/notifications/notifications.client.js.map +1 -1
  71. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs +1 -0
  72. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs.map +1 -1
  73. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js +2 -1
  74. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js.map +1 -1
  75. package/dist/martyrs/src/modules/orders/components/pages/OrderCreateBackoffice.vue.cjs +1 -1
  76. package/dist/martyrs/src/modules/orders/components/pages/OrderCreateBackoffice.vue.js +1 -1
  77. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.cjs +1 -1
  78. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.cjs.map +1 -1
  79. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.js +1 -1
  80. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.js.map +1 -1
  81. package/dist/martyrs/src/modules/orders/components/sections/AskToLogin.vue.cjs +2 -2
  82. package/dist/martyrs/src/modules/orders/components/sections/AskToLogin.vue.cjs.map +1 -1
  83. package/dist/martyrs/src/modules/orders/components/sections/AskToLogin.vue.js +2 -2
  84. package/dist/martyrs/src/modules/orders/components/sections/AskToLogin.vue.js.map +1 -1
  85. package/dist/martyrs/src/modules/organizations/components/blocks/CardOrganization.vue.cjs +12 -16
  86. package/dist/martyrs/src/modules/organizations/components/blocks/CardOrganization.vue.cjs.map +1 -1
  87. package/dist/martyrs/src/modules/organizations/components/blocks/CardOrganization.vue.js +15 -19
  88. package/dist/martyrs/src/modules/organizations/components/blocks/CardOrganization.vue.js.map +1 -1
  89. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationBackoffice.vue.cjs +1 -1
  90. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationBackoffice.vue.js +1 -1
  91. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationEdit.vue.cjs +1 -1
  92. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationEdit.vue.js +1 -1
  93. package/dist/martyrs/src/modules/products/components/blocks/CardPosition.vue.cjs +1 -1
  94. package/dist/martyrs/src/modules/products/components/blocks/CardPosition.vue.js +1 -1
  95. package/dist/martyrs/src/modules/products/components/pages/EditLeftover.vue.cjs +1 -1
  96. package/dist/martyrs/src/modules/products/components/pages/EditLeftover.vue.js +1 -1
  97. package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs +3 -3
  98. package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs.map +1 -1
  99. package/dist/martyrs/src/modules/products/components/pages/Product.vue.js +3 -3
  100. package/dist/martyrs/src/modules/products/components/pages/Product.vue.js.map +1 -1
  101. package/dist/martyrs/src/modules/products/components/pages/ProductEdit.vue.cjs +1 -1
  102. package/dist/martyrs/src/modules/products/components/pages/ProductEdit.vue.js +1 -1
  103. package/dist/martyrs/src/modules/rents/views/components/pages/RentsEdit.vue.cjs +1 -1
  104. package/dist/martyrs/src/modules/rents/views/components/pages/RentsEdit.vue.js +1 -1
  105. package/dist/martyrs.cjs.js +1 -1
  106. package/dist/martyrs.css +1 -1
  107. package/dist/martyrs.es.js +1 -1
  108. package/dist/notifications.server.js +2 -2
  109. package/dist/notifications.server.mjs +2 -2
  110. package/dist/orders.server.js +124 -109
  111. package/dist/orders.server.mjs +124 -109
  112. package/dist/style.css +12 -99
  113. package/package.json +1 -1
  114. package/src/components/Feed/Feed.vue +1 -1
  115. package/src/modules/chats/components/sections/ChatWindow.vue +1 -0
  116. package/src/modules/chats/routes/chats.routes.js +10 -20
  117. package/src/modules/chats/store/chat.store.js +1 -1
  118. package/src/modules/community/components/layouts/Community.vue +2 -5
  119. package/src/modules/community/components/sections/Comment.vue +1 -1
  120. package/src/modules/globals/controllers/classes/globals.websocket.js +116 -0
  121. package/src/modules/globals/globals.server.js +3 -0
  122. package/src/modules/globals/views/components/blocks/CardHeader.vue +1 -1
  123. package/src/modules/globals/views/components/partials/Navigation.vue +67 -149
  124. package/src/modules/globals/views/components/partials/Sidebar.vue +7 -37
  125. package/src/modules/globals/views/plugins/AlertDialog.vue +1 -1
  126. package/src/modules/icons/entities/IconTime.vue +1 -1
  127. package/src/modules/notifications/notifications.client.js +2 -79
  128. package/src/modules/notifications/services/notification.service.js +1 -1
  129. package/src/modules/orders/components/pages/OrderCreate.vue +6 -1
  130. package/src/modules/orders/components/partials/ShopCart.vue +1 -1
  131. package/src/modules/orders/components/sections/AskToLogin.vue +2 -1
  132. package/src/modules/orders/controllers/orders.controller.js +49 -35
  133. package/src/modules/organizations/components/blocks/CardOrganization.vue +10 -9
  134. package/src/modules/products/components/pages/Product.vue +3 -3
  135. package/src/styles/base/all.scss +19 -5
  136. package/src/styles/base/shadow_transitions_hover_refactor.scss +0 -30
  137. package/src/styles/base/transitions.scss +109 -0
  138. package/dist/martyrs/src/components/SelectMulti/SelectMulti.vue2.cjs.map +0 -1
  139. package/src/components/AskToLogin/AskToLogin.vue +0 -22
@@ -1,5 +1,5 @@
1
1
  import { ref as u, computed as m, onMounted as N, onUnmounted as P, createElementBlock as c, openBlock as d, createCommentVNode as f, mergeProps as V, createElementVNode as S, toDisplayString as q } from "vue";
2
- import { _ as z } from "./main-DbrX42CV.mjs";
2
+ import { _ as z } from "./main-Q8Dr1-HT.mjs";
3
3
  const D = { class: "media-container" }, T = ["src", "data-src", "alt"], U = ["controls", "loop", "muted", "autoplay", "playsinline", "preload"], _ = ["src", "type"], $ = {
4
4
  key: 2,
5
5
  class: "media-placeholder"
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),V=require("./main-DviXUDiB.js"),C={class:"media-container"},M=["src","data-src","alt"],j=["controls","loop","muted","autoplay","playsinline","preload"],N=["src","type"],O={key:2,class:"media-placeholder"},P={key:3,class:"media-error"},S={__name:"Media",props:{url:{type:String,required:!0},options:{type:Object,default:()=>({muted:!0,loop:!0,playsinline:!0,preload:"metadata"})}},setup(t){const m=t,l=e.ref(null),p=e.ref(null),s=e.ref(!1),u=e.ref(null),v=e.ref(!1);let i=null,f=!1;const d=e.computed(()=>{var o,a,n;return(n=(a=(o=m.url)==null?void 0:o.split("."))==null?void 0:a.pop())==null?void 0:n.toLowerCase()}),g=e.computed(()=>["jpg","jpeg","png","gif","webp","svg","avif"].includes(d.value)),y=e.computed(()=>["mp4","webm","ogg"].includes(d.value)),x=e.computed(()=>({mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg"})[d.value]||"");function E(){s.value=!0}function I(o){u.value=`Ошибка загрузки медиа: ${o.message}`,s.value=!1}async function w(){if(l.value)try{l.value.paused&&!f&&(await l.value.play(),f=!0)}catch(o){I(o)}}function L(){const o={root:null,rootMargin:"50px",threshold:.1};i=new IntersectionObserver(n=>{n.forEach(r=>{var c;v.value=r.isIntersecting,r.isIntersecting&&(y.value&&((c=m.options)!=null&&c.autoplay)&&w(),i.disconnect())})},o);const a=g.value?p.value:l.value;a&&i.observe(a)}return e.onMounted(()=>{L()}),e.onUnmounted(()=>{i&&i.disconnect()}),(o,a)=>{var n,r,c,k,h,b,B;return e.openBlock(),e.createElementBlock("div",C,[g.value?(e.openBlock(),e.createElementBlock("img",e.mergeProps({key:0,src:v.value?t.url:"","data-src":t.url,alt:((n=t.options)==null?void 0:n.alt)||"Image",class:["media-item",{loading:!s.value}],loading:"lazy",onLoad:E},t.options,{ref_key:"imageElement",ref:p}),null,16,M)):y.value?(e.openBlock(),e.createElementBlock("video",e.mergeProps({key:1,ref_key:"videoElement",ref:l,class:[{loading:!s.value},"media-item"],controls:!((r=t.options)!=null&&r.hideControls),loop:((c=t.options)==null?void 0:c.loop)!==!1,muted:((k=t.options)==null?void 0:k.muted)!==!1,autoplay:(h=t.options)==null?void 0:h.autoplay,playsinline:((b=t.options)==null?void 0:b.playsinline)!==!1,preload:((B=t.options)==null?void 0:B.preload)||"metadata",onLoadeddata:E},t.options),[e.createElementVNode("source",{src:t.url,type:x.value},null,8,N)],16,j)):e.createCommentVNode("",!0),s.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",O," Loading... ")),u.value?(e.openBlock(),e.createElementBlock("div",P,e.toDisplayString(u.value),1)):e.createCommentVNode("",!0)])}}},q=V._export_sfc(S,[["__scopeId","data-v-1f94a0e9"]]);exports.default=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),V=require("./main-DIXWgUWx.js"),C={class:"media-container"},M=["src","data-src","alt"],j=["controls","loop","muted","autoplay","playsinline","preload"],N=["src","type"],O={key:2,class:"media-placeholder"},P={key:3,class:"media-error"},S={__name:"Media",props:{url:{type:String,required:!0},options:{type:Object,default:()=>({muted:!0,loop:!0,playsinline:!0,preload:"metadata"})}},setup(t){const m=t,l=e.ref(null),p=e.ref(null),s=e.ref(!1),u=e.ref(null),v=e.ref(!1);let i=null,f=!1;const d=e.computed(()=>{var o,a,n;return(n=(a=(o=m.url)==null?void 0:o.split("."))==null?void 0:a.pop())==null?void 0:n.toLowerCase()}),g=e.computed(()=>["jpg","jpeg","png","gif","webp","svg","avif"].includes(d.value)),y=e.computed(()=>["mp4","webm","ogg"].includes(d.value)),x=e.computed(()=>({mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg"})[d.value]||"");function E(){s.value=!0}function I(o){u.value=`Ошибка загрузки медиа: ${o.message}`,s.value=!1}async function w(){if(l.value)try{l.value.paused&&!f&&(await l.value.play(),f=!0)}catch(o){I(o)}}function L(){const o={root:null,rootMargin:"50px",threshold:.1};i=new IntersectionObserver(n=>{n.forEach(r=>{var c;v.value=r.isIntersecting,r.isIntersecting&&(y.value&&((c=m.options)!=null&&c.autoplay)&&w(),i.disconnect())})},o);const a=g.value?p.value:l.value;a&&i.observe(a)}return e.onMounted(()=>{L()}),e.onUnmounted(()=>{i&&i.disconnect()}),(o,a)=>{var n,r,c,k,h,b,B;return e.openBlock(),e.createElementBlock("div",C,[g.value?(e.openBlock(),e.createElementBlock("img",e.mergeProps({key:0,src:v.value?t.url:"","data-src":t.url,alt:((n=t.options)==null?void 0:n.alt)||"Image",class:["media-item",{loading:!s.value}],loading:"lazy",onLoad:E},t.options,{ref_key:"imageElement",ref:p}),null,16,M)):y.value?(e.openBlock(),e.createElementBlock("video",e.mergeProps({key:1,ref_key:"videoElement",ref:l,class:[{loading:!s.value},"media-item"],controls:!((r=t.options)!=null&&r.hideControls),loop:((c=t.options)==null?void 0:c.loop)!==!1,muted:((k=t.options)==null?void 0:k.muted)!==!1,autoplay:(h=t.options)==null?void 0:h.autoplay,playsinline:((b=t.options)==null?void 0:b.playsinline)!==!1,preload:((B=t.options)==null?void 0:B.preload)||"metadata",onLoadeddata:E},t.options),[e.createElementVNode("source",{src:t.url,type:x.value},null,8,N)],16,j)):e.createCommentVNode("",!0),s.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",O," Loading... ")),u.value?(e.openBlock(),e.createElementBlock("div",P,e.toDisplayString(u.value),1)):e.createCommentVNode("",!0)])}}},q=V._export_sfc(S,[["__scopeId","data-v-1f94a0e9"]]);exports.default=q;
@@ -45,24 +45,17 @@ function requireChats_routes() {
45
45
  chats_routes = function(app, db, wss) {
46
46
  const controller = controllerFactory(db);
47
47
  const { verifySignUp, verifyUser } = middlewareFactory(db);
48
- wss.on("connection", (ws) => {
49
- ws.type = "chat";
50
- console.log("ws connecting to chat...");
51
- ws.on("message", async (message) => {
52
- const msg = JSON.parse(message);
53
- if (msg.type === "joinChat") {
54
- ws.chatId = msg.chatId;
55
- console.log(`Client joined chat: ${msg.chatId}`);
56
- } else {
57
- console.log(msg);
58
- const savedMessage = await controller.saveMessage(msg);
59
- wss.clients.forEach((client) => {
60
- if (client.type === "chat" && client.chatId && client.chatId.toString() === msg.chatId) {
61
- client.send(JSON.stringify(savedMessage));
62
- }
63
- });
64
- }
65
- });
48
+ wss.registerModule("chat", async (ws, msg) => {
49
+ if (msg.type === "joinChat") {
50
+ ws.chatId = msg.chatId;
51
+ } else {
52
+ const savedMessage = await controller.saveMessage(msg);
53
+ wss.broadcastToModuleWithFilter(
54
+ "chat",
55
+ (client) => client.chatId === msg.chatId,
56
+ savedMessage
57
+ );
58
+ }
66
59
  });
67
60
  app.use(function(req, res, next) {
68
61
  res.header(
@@ -44,24 +44,17 @@ function requireChats_routes() {
44
44
  chats_routes = function(app, db, wss) {
45
45
  const controller = controllerFactory(db);
46
46
  const { verifySignUp, verifyUser } = middlewareFactory(db);
47
- wss.on("connection", (ws) => {
48
- ws.type = "chat";
49
- console.log("ws connecting to chat...");
50
- ws.on("message", async (message) => {
51
- const msg = JSON.parse(message);
52
- if (msg.type === "joinChat") {
53
- ws.chatId = msg.chatId;
54
- console.log(`Client joined chat: ${msg.chatId}`);
55
- } else {
56
- console.log(msg);
57
- const savedMessage = await controller.saveMessage(msg);
58
- wss.clients.forEach((client) => {
59
- if (client.type === "chat" && client.chatId && client.chatId.toString() === msg.chatId) {
60
- client.send(JSON.stringify(savedMessage));
61
- }
62
- });
63
- }
64
- });
47
+ wss.registerModule("chat", async (ws, msg) => {
48
+ if (msg.type === "joinChat") {
49
+ ws.chatId = msg.chatId;
50
+ } else {
51
+ const savedMessage = await controller.saveMessage(msg);
52
+ wss.broadcastToModuleWithFilter(
53
+ "chat",
54
+ (client) => client.chatId === msg.chatId,
55
+ savedMessage
56
+ );
57
+ }
65
58
  });
66
59
  app.use(function(req, res, next) {
67
60
  res.header(
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  const _commonjsHelpers = require("./_commonjsHelpers-DHfMLFPC.js");
3
3
  const globals_abac = require("./globals.abac-DT0VjfaZ.js");
4
+ const require$$0 = require("ws");
5
+ const require$$0$1 = require("jsonwebtoken");
4
6
  var globals_policies;
5
7
  var hasRequiredGlobals_policies;
6
8
  function requireGlobals_policies() {
@@ -46,6 +48,105 @@ function requireGlobals_policies() {
46
48
  };
47
49
  return globals_policies;
48
50
  }
51
+ var globals_websocket;
52
+ var hasRequiredGlobals_websocket;
53
+ function requireGlobals_websocket() {
54
+ if (hasRequiredGlobals_websocket) return globals_websocket;
55
+ hasRequiredGlobals_websocket = 1;
56
+ const { WebSocketServer } = require$$0;
57
+ const jwt = require$$0$1;
58
+ class WebSocketManager {
59
+ constructor(server) {
60
+ this.wss = new WebSocketServer({
61
+ server,
62
+ verifyClient: this.verifyClient.bind(this)
63
+ });
64
+ this.modules = /* @__PURE__ */ new Map();
65
+ this.userConnections = /* @__PURE__ */ new Map();
66
+ this.wss.on("connection", (ws, req) => {
67
+ ws.moduleName = null;
68
+ ws.userId = req.userId || null;
69
+ if (ws.userId) {
70
+ this._trackUserConnection(ws.userId, ws);
71
+ }
72
+ ws.on("message", async (rawMessage) => {
73
+ try {
74
+ const msg = JSON.parse(rawMessage);
75
+ console.log(msg);
76
+ const moduleName = ws.moduleName || msg.module;
77
+ console.log("module name is,", moduleName);
78
+ console.log("modules is,", this.modules);
79
+ if (moduleName && this.modules.has(moduleName)) {
80
+ ws.moduleName = moduleName;
81
+ const handler = this.modules.get(moduleName);
82
+ await handler(ws, msg);
83
+ }
84
+ } catch (err) {
85
+ console.error("Invalid message or handler error:", err);
86
+ }
87
+ });
88
+ ws.on("close", () => {
89
+ if (ws.userId && this.userConnections.has(ws.userId)) {
90
+ this.userConnections.get(ws.userId).delete(ws);
91
+ if (this.userConnections.get(ws.userId).size === 0) {
92
+ this.userConnections.delete(ws.userId);
93
+ }
94
+ }
95
+ });
96
+ });
97
+ }
98
+ verifyClient(info, done) {
99
+ try {
100
+ const userCookie = info.req.headers.cookie?.split("; ").find((cookie) => cookie.startsWith("user="));
101
+ if (!userCookie) return done(true);
102
+ const token = JSON.parse(decodeURIComponent(userCookie.replace("user=", "")));
103
+ const decoded = jwt.verify(token.accessToken, process.env.SECRET_KEY);
104
+ info.req.userId = decoded._id;
105
+ } catch (err) {
106
+ console.error("Invalid token:", err);
107
+ }
108
+ done(true);
109
+ }
110
+ _trackUserConnection(userId, ws) {
111
+ if (!this.userConnections.has(userId)) {
112
+ this.userConnections.set(userId, /* @__PURE__ */ new Set());
113
+ }
114
+ this.userConnections.get(userId).add(ws);
115
+ }
116
+ registerModule(moduleName, handler) {
117
+ this.modules.set(moduleName, handler);
118
+ }
119
+ sendToUserInModule(moduleName, userId, data) {
120
+ const sockets = this.userConnections.get(userId);
121
+ if (!sockets) return;
122
+ for (const ws of sockets) {
123
+ if (ws.readyState === 1 && ws.moduleName === moduleName) {
124
+ ws.send(JSON.stringify(data));
125
+ }
126
+ }
127
+ }
128
+ broadcastToModule(moduleName, data) {
129
+ for (const ws of this.wss.clients) {
130
+ if (ws.readyState === 1 && ws.moduleName === moduleName) {
131
+ ws.send(JSON.stringify(data));
132
+ }
133
+ }
134
+ }
135
+ broadcastToModuleWithFilter(moduleName, filterFn, data) {
136
+ for (const ws of this.wss.clients) {
137
+ if (ws.readyState !== 1) continue;
138
+ if (ws.moduleName !== moduleName) continue;
139
+ if (!filterFn(ws)) continue;
140
+ ws.send(JSON.stringify(data));
141
+ }
142
+ }
143
+ getServer() {
144
+ return this.wss;
145
+ }
146
+ }
147
+ globals_websocket = WebSocketManager;
148
+ return globals_websocket;
149
+ }
49
150
  var globals_server$1;
50
151
  var hasRequiredGlobals_server;
51
152
  function requireGlobals_server() {
@@ -53,6 +154,7 @@ function requireGlobals_server() {
53
154
  hasRequiredGlobals_server = 1;
54
155
  const { getInstance } = globals_abac.requireGlobals_abac();
55
156
  const initGlobalsPolicies = requireGlobals_policies();
157
+ const Websocket = requireGlobals_websocket();
56
158
  function initializeGlobals(app, db, origins, publicPath) {
57
159
  db.log = db.mongoose.models.Log || db.mongoose.model("Log", new db.mongoose.Schema({
58
160
  timestamp: { type: Date, default: Date.now },
@@ -63,7 +165,8 @@ function requireGlobals_server() {
63
165
  initGlobalsPolicies(abac);
64
166
  }
65
167
  globals_server$1 = {
66
- initialize: initializeGlobals
168
+ initialize: initializeGlobals,
169
+ Websocket
67
170
  };
68
171
  return globals_server$1;
69
172
  }
@@ -1,5 +1,7 @@
1
1
  import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-CUmg6egw.mjs";
2
2
  import { r as requireGlobals_abac } from "./globals.abac-CvmZM8XG.mjs";
3
+ import require$$0 from "ws";
4
+ import require$$0$1 from "jsonwebtoken";
3
5
  var globals_policies;
4
6
  var hasRequiredGlobals_policies;
5
7
  function requireGlobals_policies() {
@@ -45,6 +47,105 @@ function requireGlobals_policies() {
45
47
  };
46
48
  return globals_policies;
47
49
  }
50
+ var globals_websocket;
51
+ var hasRequiredGlobals_websocket;
52
+ function requireGlobals_websocket() {
53
+ if (hasRequiredGlobals_websocket) return globals_websocket;
54
+ hasRequiredGlobals_websocket = 1;
55
+ const { WebSocketServer } = require$$0;
56
+ const jwt = require$$0$1;
57
+ class WebSocketManager {
58
+ constructor(server) {
59
+ this.wss = new WebSocketServer({
60
+ server,
61
+ verifyClient: this.verifyClient.bind(this)
62
+ });
63
+ this.modules = /* @__PURE__ */ new Map();
64
+ this.userConnections = /* @__PURE__ */ new Map();
65
+ this.wss.on("connection", (ws, req) => {
66
+ ws.moduleName = null;
67
+ ws.userId = req.userId || null;
68
+ if (ws.userId) {
69
+ this._trackUserConnection(ws.userId, ws);
70
+ }
71
+ ws.on("message", async (rawMessage) => {
72
+ try {
73
+ const msg = JSON.parse(rawMessage);
74
+ console.log(msg);
75
+ const moduleName = ws.moduleName || msg.module;
76
+ console.log("module name is,", moduleName);
77
+ console.log("modules is,", this.modules);
78
+ if (moduleName && this.modules.has(moduleName)) {
79
+ ws.moduleName = moduleName;
80
+ const handler = this.modules.get(moduleName);
81
+ await handler(ws, msg);
82
+ }
83
+ } catch (err) {
84
+ console.error("Invalid message or handler error:", err);
85
+ }
86
+ });
87
+ ws.on("close", () => {
88
+ if (ws.userId && this.userConnections.has(ws.userId)) {
89
+ this.userConnections.get(ws.userId).delete(ws);
90
+ if (this.userConnections.get(ws.userId).size === 0) {
91
+ this.userConnections.delete(ws.userId);
92
+ }
93
+ }
94
+ });
95
+ });
96
+ }
97
+ verifyClient(info, done) {
98
+ try {
99
+ const userCookie = info.req.headers.cookie?.split("; ").find((cookie) => cookie.startsWith("user="));
100
+ if (!userCookie) return done(true);
101
+ const token = JSON.parse(decodeURIComponent(userCookie.replace("user=", "")));
102
+ const decoded = jwt.verify(token.accessToken, process.env.SECRET_KEY);
103
+ info.req.userId = decoded._id;
104
+ } catch (err) {
105
+ console.error("Invalid token:", err);
106
+ }
107
+ done(true);
108
+ }
109
+ _trackUserConnection(userId, ws) {
110
+ if (!this.userConnections.has(userId)) {
111
+ this.userConnections.set(userId, /* @__PURE__ */ new Set());
112
+ }
113
+ this.userConnections.get(userId).add(ws);
114
+ }
115
+ registerModule(moduleName, handler) {
116
+ this.modules.set(moduleName, handler);
117
+ }
118
+ sendToUserInModule(moduleName, userId, data) {
119
+ const sockets = this.userConnections.get(userId);
120
+ if (!sockets) return;
121
+ for (const ws of sockets) {
122
+ if (ws.readyState === 1 && ws.moduleName === moduleName) {
123
+ ws.send(JSON.stringify(data));
124
+ }
125
+ }
126
+ }
127
+ broadcastToModule(moduleName, data) {
128
+ for (const ws of this.wss.clients) {
129
+ if (ws.readyState === 1 && ws.moduleName === moduleName) {
130
+ ws.send(JSON.stringify(data));
131
+ }
132
+ }
133
+ }
134
+ broadcastToModuleWithFilter(moduleName, filterFn, data) {
135
+ for (const ws of this.wss.clients) {
136
+ if (ws.readyState !== 1) continue;
137
+ if (ws.moduleName !== moduleName) continue;
138
+ if (!filterFn(ws)) continue;
139
+ ws.send(JSON.stringify(data));
140
+ }
141
+ }
142
+ getServer() {
143
+ return this.wss;
144
+ }
145
+ }
146
+ globals_websocket = WebSocketManager;
147
+ return globals_websocket;
148
+ }
48
149
  var globals_server$1;
49
150
  var hasRequiredGlobals_server;
50
151
  function requireGlobals_server() {
@@ -52,6 +153,7 @@ function requireGlobals_server() {
52
153
  hasRequiredGlobals_server = 1;
53
154
  const { getInstance } = requireGlobals_abac();
54
155
  const initGlobalsPolicies = requireGlobals_policies();
156
+ const Websocket = requireGlobals_websocket();
55
157
  function initializeGlobals(app, db, origins, publicPath) {
56
158
  db.log = db.mongoose.models.Log || db.mongoose.model("Log", new db.mongoose.Schema({
57
159
  timestamp: { type: Date, default: Date.now },
@@ -62,7 +164,8 @@ function requireGlobals_server() {
62
164
  initGlobalsPolicies(abac);
63
165
  }
64
166
  globals_server$1 = {
65
- initialize: initializeGlobals
167
+ initialize: initializeGlobals,
168
+ Websocket
66
169
  };
67
170
  return globals_server$1;
68
171
  }