@carlonicora/nextjs-jsonapi 1.0.4 → 1.0.5

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 (282) hide show
  1. package/dist/{AbstractService-BKlpJA61.d.mts → AbstractService-B2n_JdiC.d.mts} +1 -1
  2. package/dist/{AbstractService-D9eSVKNa.d.ts → AbstractService-DtQTYovo.d.ts} +1 -1
  3. package/dist/{content.interface-Dg2lt_An.d.mts → AuthComponent-CPLvEerw.d.mts} +11 -15
  4. package/dist/{content.interface-BhyAiOFq.d.ts → AuthComponent-m6Qp4Hz6.d.ts} +11 -15
  5. package/dist/{BlockNoteEditor-UVO3VZZE.mjs → BlockNoteEditor-BLVXQPXV.mjs} +14 -18
  6. package/dist/{BlockNoteEditor-UVO3VZZE.mjs.map → BlockNoteEditor-BLVXQPXV.mjs.map} +1 -1
  7. package/dist/{BlockNoteEditor-VFWG6LXI.js → BlockNoteEditor-ZTDHULFT.js} +15 -19
  8. package/dist/BlockNoteEditor-ZTDHULFT.js.map +1 -0
  9. package/dist/JsonApiRequest-O7BGUMFO.mjs +23 -0
  10. package/dist/JsonApiRequest-VARLNKAF.js +23 -0
  11. package/dist/JsonApiRequest-VARLNKAF.js.map +1 -0
  12. package/dist/chunk-2LM6LCJW.mjs +1 -0
  13. package/dist/chunk-3APORDYP.mjs +7783 -0
  14. package/dist/chunk-3APORDYP.mjs.map +1 -0
  15. package/dist/{chunk-TMVHSY3Y.js → chunk-5ZEADNNP.js} +36 -17
  16. package/dist/chunk-5ZEADNNP.js.map +1 -0
  17. package/dist/{chunk-ECDTZBYO.mjs → chunk-74F6BBHH.mjs} +21 -2
  18. package/dist/chunk-74F6BBHH.mjs.map +1 -0
  19. package/dist/{chunk-GYWPEPOH.mjs → chunk-7C5RAEBO.mjs} +72 -68
  20. package/dist/chunk-7C5RAEBO.mjs.map +1 -0
  21. package/dist/chunk-A5DDIABK.js +1 -0
  22. package/dist/{chunk-TEGF6ZWG.js → chunk-AGAJMJ4T.js} +47 -9
  23. package/dist/chunk-AGAJMJ4T.js.map +1 -0
  24. package/dist/{chunk-CXQOWQSY.js → chunk-AYHKQWHH.js} +15 -2
  25. package/dist/chunk-AYHKQWHH.js.map +1 -0
  26. package/dist/{chunk-I2REI7OA.js → chunk-HMHGLXWC.js} +33 -15
  27. package/dist/chunk-HMHGLXWC.js.map +1 -0
  28. package/dist/chunk-IWFGEPAA.mjs +1 -0
  29. package/dist/chunk-JC3WJK65.js +1 -0
  30. package/dist/{chunk-L6EQEAXU.mjs → chunk-PYF2U6WG.mjs} +25 -7
  31. package/dist/chunk-PYF2U6WG.mjs.map +1 -0
  32. package/dist/{chunk-YDVTFM7X.mjs → chunk-RBIVEH2K.mjs} +42 -4
  33. package/dist/chunk-RBIVEH2K.mjs.map +1 -0
  34. package/dist/{chunk-V2JJPI7N.js → chunk-RZO2LOW4.js} +237 -233
  35. package/dist/chunk-RZO2LOW4.js.map +1 -0
  36. package/dist/{chunk-X4BIHJ2B.mjs → chunk-SM63SZCP.mjs} +15 -2
  37. package/dist/chunk-SM63SZCP.mjs.map +1 -0
  38. package/dist/chunk-WEC4YMOS.js +7783 -0
  39. package/dist/chunk-WEC4YMOS.js.map +1 -0
  40. package/dist/client/index.d.mts +21 -2
  41. package/dist/client/index.d.ts +21 -2
  42. package/dist/client/index.js +18 -245
  43. package/dist/client/index.js.map +1 -1
  44. package/dist/client/index.mjs +28 -255
  45. package/dist/client/index.mjs.map +1 -1
  46. package/dist/components/index.d.mts +293 -8
  47. package/dist/components/index.d.ts +293 -8
  48. package/dist/components/index.js +78 -2323
  49. package/dist/components/index.js.map +1 -1
  50. package/dist/components/index.mjs +172 -2417
  51. package/dist/components/index.mjs.map +1 -1
  52. package/dist/{config-hXufftVS.d.ts → config-BmnK65TD.d.mts} +1 -0
  53. package/dist/{config-hXufftVS.d.mts → config-BmnK65TD.d.ts} +1 -0
  54. package/dist/config-DQeAo9Kf.d.mts +49 -0
  55. package/dist/config-DQeAo9Kf.d.ts +49 -0
  56. package/dist/contexts/index.d.mts +109 -21
  57. package/dist/contexts/index.d.ts +109 -21
  58. package/dist/contexts/index.js +39 -7
  59. package/dist/contexts/index.js.map +1 -1
  60. package/dist/contexts/index.mjs +40 -8
  61. package/dist/core/index.d.mts +3 -4
  62. package/dist/core/index.d.ts +3 -4
  63. package/dist/core/index.js +3 -7
  64. package/dist/core/index.js.map +1 -1
  65. package/dist/core/index.mjs +4 -8
  66. package/dist/{d3.link.interface-QMdB22bC.d.mts → d3.link.interface-ClC4Irqp.d.mts} +2 -1
  67. package/dist/{d3.link.interface-QMdB22bC.d.ts → d3.link.interface-ClC4Irqp.d.ts} +2 -1
  68. package/dist/features/index.d.mts +17 -86
  69. package/dist/features/index.d.ts +17 -86
  70. package/dist/features/index.js +7 -16
  71. package/dist/features/index.js.map +1 -1
  72. package/dist/features/index.mjs +10 -19
  73. package/dist/hooks/index.d.mts +18 -43
  74. package/dist/hooks/index.d.ts +18 -43
  75. package/dist/hooks/index.js +20 -7
  76. package/dist/hooks/index.js.map +1 -1
  77. package/dist/hooks/index.mjs +19 -6
  78. package/dist/index.d.mts +10 -6
  79. package/dist/index.d.ts +10 -6
  80. package/dist/index.js +13 -10
  81. package/dist/index.js.map +1 -1
  82. package/dist/index.mjs +22 -19
  83. package/dist/interfaces/index.d.mts +2 -1
  84. package/dist/interfaces/index.d.ts +2 -1
  85. package/dist/notification.interface-BBgMUdLR.d.mts +14 -0
  86. package/dist/notification.interface-gyvT-Z2F.d.ts +14 -0
  87. package/dist/permissions/index.d.mts +2 -3
  88. package/dist/permissions/index.d.ts +2 -3
  89. package/dist/server/index.d.mts +38 -18
  90. package/dist/server/index.d.ts +38 -18
  91. package/dist/server/index.js +70 -2
  92. package/dist/server/index.js.map +1 -1
  93. package/dist/server/index.mjs +68 -0
  94. package/dist/server/index.mjs.map +1 -1
  95. package/dist/types-BUAlgqqh.d.ts +39 -0
  96. package/dist/{types-DluCaP1I.d.ts → types-Bl61ob-7.d.mts} +19 -2
  97. package/dist/{types-lQVA8d_P.d.mts → types-Bl61ob-7.d.ts} +19 -2
  98. package/dist/types-iVdVY7ba.d.mts +39 -0
  99. package/dist/useSocket-Cn7fB_B1.d.mts +25 -0
  100. package/dist/useSocket-DzMKRKCA.d.ts +25 -0
  101. package/dist/user.fields-CbdObSmS.d.mts +18 -0
  102. package/dist/user.fields-CbdObSmS.d.ts +18 -0
  103. package/dist/utils/index.d.mts +1 -2
  104. package/dist/utils/index.d.ts +1 -2
  105. package/package.json +5 -3
  106. package/src/client/index.ts +13 -0
  107. package/src/components/forms/index.ts +1 -0
  108. package/src/components/index.ts +5 -0
  109. package/src/components/tables/ContentListTable.tsx +1 -0
  110. package/src/contexts/CommonContext.tsx +52 -0
  111. package/src/contexts/SharedContext.tsx +2 -0
  112. package/src/contexts/SocketContext.tsx +65 -0
  113. package/src/contexts/index.ts +6 -1
  114. package/src/features/auth/components/containers/AuthContainer.tsx +32 -0
  115. package/src/features/auth/components/containers/index.ts +1 -0
  116. package/src/features/auth/components/details/LandingComponent.tsx +39 -0
  117. package/src/features/auth/components/details/index.ts +1 -0
  118. package/src/features/auth/components/forms/AcceptInvitation.tsx +136 -0
  119. package/src/features/auth/components/forms/ActivateAccount.tsx +75 -0
  120. package/src/features/auth/components/forms/Cookies.tsx +32 -0
  121. package/src/features/auth/components/forms/ForgotPassword.tsx +108 -0
  122. package/src/features/auth/components/forms/Login.tsx +118 -0
  123. package/src/features/auth/components/forms/Logout.tsx +19 -0
  124. package/src/features/auth/components/forms/RefreshUser.tsx +39 -0
  125. package/src/features/auth/components/forms/Register.tsx +150 -0
  126. package/src/features/auth/components/forms/ResetPassword.tsx +126 -0
  127. package/src/features/auth/components/forms/index.ts +9 -0
  128. package/src/features/auth/components/index.ts +3 -0
  129. package/src/features/auth/contexts/AuthContext.tsx +77 -0
  130. package/src/features/auth/contexts/index.ts +1 -0
  131. package/src/features/auth/enums/AuthComponent.ts +9 -0
  132. package/src/features/auth/enums/index.ts +1 -0
  133. package/src/features/auth/index.ts +2 -1
  134. package/src/features/auth/utils/AuthCookies.ts +134 -0
  135. package/src/features/auth/utils/index.ts +1 -0
  136. package/src/features/company/components/containers/AdminCompanyContainer.tsx +26 -0
  137. package/src/features/company/components/containers/CompanyContainer.tsx +17 -0
  138. package/src/features/company/components/containers/index.ts +2 -0
  139. package/src/features/company/components/details/CompanyDetails.tsx +26 -0
  140. package/src/features/company/components/details/index.ts +1 -0
  141. package/src/features/company/components/forms/CompanyConfigurationEditor.tsx +151 -0
  142. package/src/features/company/components/forms/CompanyConfigurationSecurityForm.tsx +97 -0
  143. package/src/features/company/components/forms/CompanyDeleter.tsx +121 -0
  144. package/src/features/company/components/forms/CompanyEditor.tsx +245 -0
  145. package/src/features/company/components/forms/CompanyLicense.tsx +213 -0
  146. package/src/features/company/components/forms/index.ts +5 -0
  147. package/src/features/company/components/index.ts +4 -0
  148. package/src/features/company/components/lists/CompaniesList.tsx +31 -0
  149. package/src/features/company/components/lists/index.ts +1 -0
  150. package/src/features/company/contexts/CompanyContext.tsx +99 -0
  151. package/src/features/company/contexts/index.ts +0 -0
  152. package/src/features/company/hooks/index.ts +1 -0
  153. package/src/features/company/hooks/useCompanyTableStructure.tsx +82 -0
  154. package/src/features/feature/components/forms/FormFeatures.tsx +141 -140
  155. package/src/features/feature/components/forms/index.ts +1 -0
  156. package/src/features/feature/components/index.ts +1 -1
  157. package/src/features/feature/index.ts +1 -2
  158. package/src/features/module/index.ts +1 -1
  159. package/src/features/notification/components/common/NotificationErrorBoundary.tsx +51 -0
  160. package/src/features/notification/components/common/index.ts +1 -0
  161. package/src/features/notification/components/containers/NotificationsListContainer.tsx +44 -0
  162. package/src/features/notification/components/containers/index.ts +1 -0
  163. package/src/features/notification/components/index.ts +5 -0
  164. package/src/features/notification/components/lists/NotificationsList.tsx +129 -0
  165. package/src/features/notification/components/lists/index.ts +1 -0
  166. package/src/features/notification/components/modals/NotificationModal.tsx +220 -0
  167. package/src/features/notification/components/modals/index.ts +1 -0
  168. package/src/features/notification/components/notifications/Notification.tsx +120 -0
  169. package/src/features/notification/components/notifications/PushNotificationProvider.tsx +9 -0
  170. package/src/features/notification/components/notifications/index.ts +2 -0
  171. package/src/features/notification/contexts/NotificationContext.tsx +187 -0
  172. package/src/features/notification/contexts/index.ts +1 -0
  173. package/src/features/notification/index.ts +1 -1
  174. package/src/features/push/index.ts +1 -1
  175. package/src/features/role/components/containers/RoleContainer.tsx +18 -0
  176. package/src/features/role/components/containers/index.ts +1 -0
  177. package/src/features/role/components/details/RoleDetails.tsx +21 -0
  178. package/src/features/role/components/details/index.ts +1 -0
  179. package/src/features/role/components/forms/FormRoles.tsx +82 -0
  180. package/src/features/role/components/forms/RemoveUserFromRole.tsx +108 -0
  181. package/src/features/role/components/forms/UserRoleAdd.tsx +128 -0
  182. package/src/features/role/components/forms/index.ts +3 -0
  183. package/src/features/role/components/index.ts +4 -0
  184. package/src/features/role/components/lists/RolesList.tsx +27 -0
  185. package/src/features/role/components/lists/UserRolesList.tsx +31 -0
  186. package/src/features/role/components/lists/index.ts +2 -0
  187. package/src/features/role/contexts/RoleContext.tsx +84 -0
  188. package/src/features/role/contexts/index.ts +1 -0
  189. package/src/features/role/hooks/index.ts +1 -0
  190. package/src/features/role/hooks/useRoleTableStructure.tsx +72 -0
  191. package/src/features/s3/index.ts +1 -1
  192. package/src/features/user/components/containers/UserContainer.tsx +23 -0
  193. package/src/features/user/components/containers/UserIndexContainer.tsx +12 -0
  194. package/src/features/user/components/containers/UsersListContainer.tsx +36 -0
  195. package/src/features/user/components/containers/index.ts +3 -0
  196. package/src/features/user/components/details/UserDetails.tsx +74 -0
  197. package/src/features/user/components/details/UserIndexDetails.tsx +28 -0
  198. package/src/features/user/components/details/index.ts +2 -0
  199. package/src/features/user/components/forms/RoleUserAdd.tsx +93 -0
  200. package/src/features/user/components/forms/UserAvatarEditor.tsx +78 -0
  201. package/src/features/user/components/forms/UserDeleter.tsx +49 -0
  202. package/src/features/user/components/forms/UserEditor.tsx +319 -0
  203. package/src/features/user/components/forms/UserMultiSelect.tsx +218 -0
  204. package/src/features/user/components/forms/UserReactivator.tsx +79 -0
  205. package/src/features/user/components/forms/UserResentInvitationEmail.tsx +88 -0
  206. package/src/features/user/components/forms/UserSelector.tsx +185 -0
  207. package/src/features/user/components/forms/index.ts +8 -0
  208. package/src/features/user/components/index.ts +3 -0
  209. package/src/features/user/components/lists/AdminUsersList.tsx +41 -0
  210. package/src/features/user/components/lists/CompanyUsersList.tsx +44 -0
  211. package/src/features/user/components/lists/RelevantUsersList.tsx +30 -0
  212. package/src/features/user/components/lists/RoleUsersList.tsx +31 -0
  213. package/src/features/user/components/lists/UserListInAdd.tsx +53 -0
  214. package/src/features/user/components/lists/UsersList.tsx +30 -0
  215. package/src/features/user/components/lists/UsersListByContentIds.tsx +30 -0
  216. package/src/features/user/components/lists/index.ts +7 -0
  217. package/src/features/user/components/widgets/UserAvatarList.tsx +31 -0
  218. package/src/features/user/components/widgets/UserSearchPopover.tsx +89 -0
  219. package/src/features/user/contexts/UserContext.tsx +106 -0
  220. package/src/features/user/contexts/index.ts +1 -0
  221. package/src/features/user/hooks/index.ts +2 -0
  222. package/src/features/user/hooks/useUserSearch.ts +53 -0
  223. package/src/features/user/hooks/useUserTableStructure.tsx +115 -0
  224. package/src/features/user/index.ts +0 -1
  225. package/src/hooks/index.ts +4 -0
  226. package/src/hooks/useCustomD3Graph.tsx +2 -0
  227. package/src/hooks/useNotificationSync.ts +20 -0
  228. package/src/hooks/usePageTracker.ts +69 -0
  229. package/src/hooks/usePushNotifications.ts +82 -0
  230. package/src/hooks/useSocket.ts +201 -0
  231. package/src/hooks/useTableGenerator.ts +6 -2
  232. package/src/i18n/config.ts +1 -0
  233. package/src/index.ts +4 -0
  234. package/src/interfaces/d3.link.interface.ts +2 -1
  235. package/src/server/ServerSession.ts +103 -0
  236. package/src/server/index.ts +2 -1
  237. package/src/unified/JsonApiRequest.ts +23 -0
  238. package/dist/ApiRequestDataTypeInterface-CUKFDBx2.d.mts +0 -20
  239. package/dist/ApiRequestDataTypeInterface-CUKFDBx2.d.ts +0 -20
  240. package/dist/BlockNoteEditor-VFWG6LXI.js.map +0 -1
  241. package/dist/JsonApiRequest-S3ICLM7B.mjs +0 -20
  242. package/dist/JsonApiRequest-ZZLSP26T.js +0 -20
  243. package/dist/JsonApiRequest-ZZLSP26T.js.map +0 -1
  244. package/dist/chunk-366S2JCC.mjs +0 -31
  245. package/dist/chunk-366S2JCC.mjs.map +0 -1
  246. package/dist/chunk-5W6AKZE6.mjs +0 -131
  247. package/dist/chunk-5W6AKZE6.mjs.map +0 -1
  248. package/dist/chunk-A3J3AAYM.mjs +0 -97
  249. package/dist/chunk-A3J3AAYM.mjs.map +0 -1
  250. package/dist/chunk-AWONBQQP.js +0 -97
  251. package/dist/chunk-AWONBQQP.js.map +0 -1
  252. package/dist/chunk-CXQOWQSY.js.map +0 -1
  253. package/dist/chunk-DKKMWBP4.mjs +0 -1
  254. package/dist/chunk-DKKMWBP4.mjs.map +0 -1
  255. package/dist/chunk-DO2HLAZO.js +0 -48
  256. package/dist/chunk-DO2HLAZO.js.map +0 -1
  257. package/dist/chunk-DZXDB3K2.mjs +0 -17
  258. package/dist/chunk-DZXDB3K2.mjs.map +0 -1
  259. package/dist/chunk-ECDTZBYO.mjs.map +0 -1
  260. package/dist/chunk-FY4SXJGU.js +0 -806
  261. package/dist/chunk-FY4SXJGU.js.map +0 -1
  262. package/dist/chunk-GYWPEPOH.mjs.map +0 -1
  263. package/dist/chunk-H6FMOA6B.js +0 -1
  264. package/dist/chunk-H6FMOA6B.js.map +0 -1
  265. package/dist/chunk-I2REI7OA.js.map +0 -1
  266. package/dist/chunk-J4Q36PMP.js +0 -31
  267. package/dist/chunk-J4Q36PMP.js.map +0 -1
  268. package/dist/chunk-L6EQEAXU.mjs.map +0 -1
  269. package/dist/chunk-MFO27OHB.mjs +0 -48
  270. package/dist/chunk-MFO27OHB.mjs.map +0 -1
  271. package/dist/chunk-RAF7PNLG.js +0 -131
  272. package/dist/chunk-RAF7PNLG.js.map +0 -1
  273. package/dist/chunk-RUR22SVM.js +0 -17
  274. package/dist/chunk-RUR22SVM.js.map +0 -1
  275. package/dist/chunk-TEGF6ZWG.js.map +0 -1
  276. package/dist/chunk-TMVHSY3Y.js.map +0 -1
  277. package/dist/chunk-V2JJPI7N.js.map +0 -1
  278. package/dist/chunk-WWWMJZEF.mjs +0 -806
  279. package/dist/chunk-WWWMJZEF.mjs.map +0 -1
  280. package/dist/chunk-X4BIHJ2B.mjs.map +0 -1
  281. package/dist/chunk-YDVTFM7X.mjs.map +0 -1
  282. /package/dist/{JsonApiRequest-S3ICLM7B.mjs.map → JsonApiRequest-O7BGUMFO.mjs.map} +0 -0
@@ -4,6 +4,9 @@ import {
4
4
  import {
5
5
  getServerToken
6
6
  } from "../chunk-YF5XQZDR.mjs";
7
+ import {
8
+ checkPermissionsFromServer
9
+ } from "../chunk-DD3KISNB.mjs";
7
10
  import {
8
11
  __name
9
12
  } from "../chunk-PAWJFY3S.mjs";
@@ -20,7 +23,72 @@ async function invalidateCacheTags(tags, profile = "max") {
20
23
  }
21
24
  }
22
25
  __name(invalidateCacheTags, "invalidateCacheTags");
26
+
27
+ // src/server/ServerSession.ts
28
+ import { cookies } from "next/headers";
29
+ import { redirect } from "next/navigation";
30
+ import zlib from "zlib";
31
+ var ServerSession = class {
32
+ static {
33
+ __name(this, "ServerSession");
34
+ }
35
+ static async isLogged() {
36
+ const cookieStore = await cookies();
37
+ const token = cookieStore.get("token");
38
+ if (!token || !token.value) return false;
39
+ return true;
40
+ }
41
+ static async isLicenseActive() {
42
+ const cookieStore = await cookies();
43
+ const licenseExpirationDate = cookieStore.get("licenseExpirationDate")?.value;
44
+ if (!licenseExpirationDate) return false;
45
+ const now = /* @__PURE__ */ new Date();
46
+ return new Date(licenseExpirationDate) > now;
47
+ }
48
+ static async companyId() {
49
+ const cookieStore = await cookies();
50
+ return cookieStore.get("companyId")?.value ?? "";
51
+ }
52
+ static async userId() {
53
+ const cookieStore = await cookies();
54
+ return cookieStore.get("userId")?.value ?? "";
55
+ }
56
+ static async checkPermission(params) {
57
+ if (!await this.hasPermissionToModule(params)) redirect(`/401`);
58
+ }
59
+ static async hasRole(roleId) {
60
+ const cookieStore = await cookies();
61
+ const roles = cookieStore.get("roles")?.value;
62
+ if (!roles || !roles.includes(roleId)) return false;
63
+ return true;
64
+ }
65
+ static async hasFeature(featureId) {
66
+ const cookieStore = await cookies();
67
+ const features = cookieStore.get("features")?.value;
68
+ if (!features || !features.includes(featureId)) return false;
69
+ return true;
70
+ }
71
+ static async hasPermissionToModule(params) {
72
+ const cookieStore = await cookies();
73
+ if (params.module.feature) {
74
+ const features = cookieStore.get("features")?.value;
75
+ if (features && !features.includes(params.module.feature)) return false;
76
+ }
77
+ const rawModules = cookieStore.get("modules")?.value;
78
+ if (!rawModules) return false;
79
+ const modules = JSON.parse(zlib.gunzipSync(Buffer.from(rawModules, "base64")).toString());
80
+ const selectedModule = modules.find((module) => module.id === params.module.moduleId);
81
+ return checkPermissionsFromServer({
82
+ module: params.module,
83
+ action: params.action,
84
+ data: params.data,
85
+ userId: await this.userId(),
86
+ selectedModule
87
+ });
88
+ }
89
+ };
23
90
  export {
91
+ ServerSession,
24
92
  getServerToken,
25
93
  invalidateCacheTag,
26
94
  invalidateCacheTags,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server/cache.ts"],"sourcesContent":["\"use server\";\n\nimport { revalidateTag } from \"next/cache\";\n\nexport type CacheProfile = \"seconds\" | \"minutes\" | \"hours\" | \"days\" | \"weeks\" | \"max\" | \"default\";\n\n/**\n * Revalidate a cache tag to invalidate cached data.\n * Next.js 16+ requires a profile parameter.\n *\n * @param tag - The cache tag to invalidate\n * @param profile - The cache profile (defaults to \"max\" for immediate invalidation)\n */\nexport async function invalidateCacheTag(tag: string, profile: CacheProfile = \"max\"): Promise<void> {\n revalidateTag(tag, profile);\n}\n\n/**\n * Revalidate multiple cache tags.\n *\n * @param tags - Array of cache tags to invalidate\n * @param profile - The cache profile (defaults to \"max\" for immediate invalidation)\n */\nexport async function invalidateCacheTags(tags: string[], profile: CacheProfile = \"max\"): Promise<void> {\n for (const tag of tags) {\n revalidateTag(tag, profile);\n }\n}\n"],"mappings":";;;;;;;;;;;AAEA,SAAS,qBAAqB;AAW9B,eAAsB,mBAAmB,KAAa,UAAwB,OAAsB;AAClG,gBAAc,KAAK,OAAO;AAC5B;AAFsB;AAUtB,eAAsB,oBAAoB,MAAgB,UAAwB,OAAsB;AACtG,aAAW,OAAO,MAAM;AACtB,kBAAc,KAAK,OAAO;AAAA,EAC5B;AACF;AAJsB;","names":[]}
1
+ {"version":3,"sources":["../../src/server/cache.ts","../../src/server/ServerSession.ts"],"sourcesContent":["\"use server\";\n\nimport { revalidateTag } from \"next/cache\";\n\nexport type CacheProfile = \"seconds\" | \"minutes\" | \"hours\" | \"days\" | \"weeks\" | \"max\" | \"default\";\n\n/**\n * Revalidate a cache tag to invalidate cached data.\n * Next.js 16+ requires a profile parameter.\n *\n * @param tag - The cache tag to invalidate\n * @param profile - The cache profile (defaults to \"max\" for immediate invalidation)\n */\nexport async function invalidateCacheTag(tag: string, profile: CacheProfile = \"max\"): Promise<void> {\n revalidateTag(tag, profile);\n}\n\n/**\n * Revalidate multiple cache tags.\n *\n * @param tags - Array of cache tags to invalidate\n * @param profile - The cache profile (defaults to \"max\" for immediate invalidation)\n */\nexport async function invalidateCacheTags(tags: string[], profile: CacheProfile = \"max\"): Promise<void> {\n for (const tag of tags) {\n revalidateTag(tag, profile);\n }\n}\n","import { cookies } from \"next/headers\";\nimport { redirect } from \"next/navigation\";\nimport zlib from \"zlib\";\nimport { Action, checkPermissionsFromServer, ModuleWithPermissions } from \"../permissions\";\n\nexport class ServerSession {\n static async isLogged() {\n const cookieStore = await cookies();\n const token = cookieStore.get(\"token\");\n\n if (!token || !token.value) return false;\n return true;\n }\n\n static async isLicenseActive(): Promise<boolean> {\n const cookieStore = await cookies();\n const licenseExpirationDate = cookieStore.get(\"licenseExpirationDate\")?.value;\n\n if (!licenseExpirationDate) return false;\n\n const now = new Date();\n return new Date(licenseExpirationDate) > now;\n }\n\n static async companyId() {\n const cookieStore = await cookies();\n return cookieStore.get(\"companyId\")?.value ?? \"\";\n }\n\n static async userId() {\n const cookieStore = await cookies();\n return cookieStore.get(\"userId\")?.value ?? \"\";\n }\n\n static async checkPermission<M extends ModuleWithPermissions>(params: { module: M; action: Action; data?: any }) {\n if (!(await this.hasPermissionToModule(params))) redirect(`/401`);\n }\n\n static async hasRole(roleId: string): Promise<boolean> {\n const cookieStore = await cookies();\n const roles = cookieStore.get(\"roles\")?.value;\n\n if (!roles || !roles.includes(roleId)) return false;\n\n return true;\n }\n\n static async hasFeature(featureId: string): Promise<boolean> {\n const cookieStore = await cookies();\n const features = cookieStore.get(\"features\")?.value;\n\n if (!features || !features.includes(featureId)) return false;\n\n return true;\n }\n\n static async hasPermissionToModule<M extends ModuleWithPermissions>(params: {\n module: M;\n action: Action;\n data?: any;\n }): Promise<boolean> {\n const cookieStore = await cookies();\n\n if (params.module.feature) {\n const features = cookieStore.get(\"features\")?.value;\n\n if (features && !features.includes(params.module.feature)) return false;\n }\n\n const rawModules = cookieStore.get(\"modules\")?.value;\n if (!rawModules) return false;\n\n const modules: {\n id: string;\n permissions: {\n create: boolean | string;\n read: boolean | string;\n update: boolean | string;\n delete: boolean | string;\n };\n }[] = JSON.parse(zlib.gunzipSync(Buffer.from(rawModules, \"base64\")).toString());\n\n const selectedModule = modules.find((module) => module.id === params.module.moduleId);\n\n return checkPermissionsFromServer({\n module: params.module,\n action: params.action,\n data: params.data,\n userId: await this.userId(),\n selectedModule: selectedModule,\n });\n\n // if (!selectedModule) return false;\n\n // if (!selectedModule.permissions[params.action]) return false;\n // if (typeof selectedModule.permissions[params.action] === \"boolean\")\n // return selectedModule.permissions[params.action] as boolean;\n\n // if (!params.data) return false;\n\n // return params.data[selectedModule.permissions[params.action] as string] === this.userId;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAEA,SAAS,qBAAqB;AAW9B,eAAsB,mBAAmB,KAAa,UAAwB,OAAsB;AAClG,gBAAc,KAAK,OAAO;AAC5B;AAFsB;AAUtB,eAAsB,oBAAoB,MAAgB,UAAwB,OAAsB;AACtG,aAAW,OAAO,MAAM;AACtB,kBAAc,KAAK,OAAO;AAAA,EAC5B;AACF;AAJsB;;;ACvBtB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,OAAO,UAAU;AAGV,IAAM,gBAAN,MAAoB;AAAA,EAL3B,OAK2B;AAAA;AAAA;AAAA,EACzB,aAAa,WAAW;AACtB,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,QAAQ,YAAY,IAAI,OAAO;AAErC,QAAI,CAAC,SAAS,CAAC,MAAM,MAAO,QAAO;AACnC,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,kBAAoC;AAC/C,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,wBAAwB,YAAY,IAAI,uBAAuB,GAAG;AAExE,QAAI,CAAC,sBAAuB,QAAO;AAEnC,UAAM,MAAM,oBAAI,KAAK;AACrB,WAAO,IAAI,KAAK,qBAAqB,IAAI;AAAA,EAC3C;AAAA,EAEA,aAAa,YAAY;AACvB,UAAM,cAAc,MAAM,QAAQ;AAClC,WAAO,YAAY,IAAI,WAAW,GAAG,SAAS;AAAA,EAChD;AAAA,EAEA,aAAa,SAAS;AACpB,UAAM,cAAc,MAAM,QAAQ;AAClC,WAAO,YAAY,IAAI,QAAQ,GAAG,SAAS;AAAA,EAC7C;AAAA,EAEA,aAAa,gBAAiD,QAAmD;AAC/G,QAAI,CAAE,MAAM,KAAK,sBAAsB,MAAM,EAAI,UAAS,MAAM;AAAA,EAClE;AAAA,EAEA,aAAa,QAAQ,QAAkC;AACrD,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,QAAQ,YAAY,IAAI,OAAO,GAAG;AAExC,QAAI,CAAC,SAAS,CAAC,MAAM,SAAS,MAAM,EAAG,QAAO;AAE9C,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,WAAW,WAAqC;AAC3D,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,WAAW,YAAY,IAAI,UAAU,GAAG;AAE9C,QAAI,CAAC,YAAY,CAAC,SAAS,SAAS,SAAS,EAAG,QAAO;AAEvD,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,sBAAuD,QAI/C;AACnB,UAAM,cAAc,MAAM,QAAQ;AAElC,QAAI,OAAO,OAAO,SAAS;AACzB,YAAM,WAAW,YAAY,IAAI,UAAU,GAAG;AAE9C,UAAI,YAAY,CAAC,SAAS,SAAS,OAAO,OAAO,OAAO,EAAG,QAAO;AAAA,IACpE;AAEA,UAAM,aAAa,YAAY,IAAI,SAAS,GAAG;AAC/C,QAAI,CAAC,WAAY,QAAO;AAExB,UAAM,UAQA,KAAK,MAAM,KAAK,WAAW,OAAO,KAAK,YAAY,QAAQ,CAAC,EAAE,SAAS,CAAC;AAE9E,UAAM,iBAAiB,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,OAAO,OAAO,QAAQ;AAEpF,WAAO,2BAA2B;AAAA,MAChC,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO;AAAA,MACb,QAAQ,MAAM,KAAK,OAAO;AAAA,MAC1B;AAAA,IACF,CAAC;AAAA,EAWH;AACF;","names":[]}
@@ -0,0 +1,39 @@
1
+ import { ColumnDef } from '@tanstack/react-table';
2
+ import { b as PageUrl } from './types-Bl61ob-7.js';
3
+ import { D as DataListRetriever } from './useDataListRetriever-futhx3OP.js';
4
+
5
+ type TableContent<T> = {
6
+ jsonApiData: T;
7
+ [key: string]: any;
8
+ };
9
+ interface TableStructureGeneratorInterface<T, U> {
10
+ generateTableStructure: (params: {
11
+ t: (key: string) => string;
12
+ generateUrl: (params: {
13
+ page: string | PageUrl | string;
14
+ id?: string;
15
+ }) => string;
16
+ data: T[];
17
+ fields: Array<U>;
18
+ checkedIds?: string[];
19
+ toggleId?: (id: string) => void;
20
+ }) => {
21
+ data: TableContent<T>[];
22
+ columns: ColumnDef<TableContent<T>>[];
23
+ };
24
+ }
25
+ type UseTableStructureHookParams<T, U> = {
26
+ data: T[];
27
+ fields: Array<U>;
28
+ checkedIds?: string[];
29
+ toggleId?: (id: string) => void;
30
+ dataRetriever?: DataListRetriever<T>;
31
+ context?: Record<string, any>;
32
+ };
33
+ type UseTableStructureHookReturn<T> = {
34
+ data: TableContent<T>[];
35
+ columns: ColumnDef<TableContent<T>>[];
36
+ };
37
+ type UseTableStructureHook<T, U> = (params: UseTableStructureHookParams<T, U>) => UseTableStructureHookReturn<T>;
38
+
39
+ export type { TableContent as T, UseTableStructureHook as U, UseTableStructureHookParams as a, UseTableStructureHookReturn as b, TableStructureGeneratorInterface as c };
@@ -1,4 +1,21 @@
1
- import { A as ApiRequestDataTypeInterface, F as FieldSelector } from './ApiRequestDataTypeInterface-CUKFDBx2.js';
1
+ type GetterKeys<T> = {
2
+ [K in keyof T]: T[K] extends () => any ? never : K;
3
+ }[keyof T];
4
+ type FieldSelector<T> = {
5
+ type: string;
6
+ fields: ReadonlyArray<GetterKeys<T>>;
7
+ };
8
+ declare function createJsonApiInclusion<T>(dataType: string, fields: ReadonlyArray<GetterKeys<T>>): FieldSelector<T>;
9
+
10
+ type ApiRequestDataTypeInterface = {
11
+ name: string;
12
+ cache?: string;
13
+ inclusions?: Record<string, {
14
+ types?: string[];
15
+ fields?: FieldSelector<any>[];
16
+ }>;
17
+ model: new () => any;
18
+ };
2
19
 
3
20
  /**
4
21
  * Permission actions
@@ -92,4 +109,4 @@ type ModuleFactory = (params: {
92
109
  }>;
93
110
  }) => ModuleWithPermissions;
94
111
 
95
- export { Action as A, type ModulePermissionDefinition as M, type PermissionCheck as P, type PageUrl as a, type ModuleDefinition as b, type PermissionConfig as c, type PermissionModule as d, type PermissionUser as e, type ModuleWithPermissions as f, type ModuleFactory as g };
112
+ export { type ApiRequestDataTypeInterface as A, type FieldSelector as F, type GetterKeys as G, type ModuleWithPermissions as M, type PermissionCheck as P, Action as a, type PageUrl as b, createJsonApiInclusion as c, type ModulePermissionDefinition as d, type ModuleDefinition as e, type PermissionConfig as f, type PermissionModule as g, type PermissionUser as h, type ModuleFactory as i };
@@ -1,4 +1,21 @@
1
- import { A as ApiRequestDataTypeInterface, F as FieldSelector } from './ApiRequestDataTypeInterface-CUKFDBx2.mjs';
1
+ type GetterKeys<T> = {
2
+ [K in keyof T]: T[K] extends () => any ? never : K;
3
+ }[keyof T];
4
+ type FieldSelector<T> = {
5
+ type: string;
6
+ fields: ReadonlyArray<GetterKeys<T>>;
7
+ };
8
+ declare function createJsonApiInclusion<T>(dataType: string, fields: ReadonlyArray<GetterKeys<T>>): FieldSelector<T>;
9
+
10
+ type ApiRequestDataTypeInterface = {
11
+ name: string;
12
+ cache?: string;
13
+ inclusions?: Record<string, {
14
+ types?: string[];
15
+ fields?: FieldSelector<any>[];
16
+ }>;
17
+ model: new () => any;
18
+ };
2
19
 
3
20
  /**
4
21
  * Permission actions
@@ -92,4 +109,4 @@ type ModuleFactory = (params: {
92
109
  }>;
93
110
  }) => ModuleWithPermissions;
94
111
 
95
- export { Action as A, type ModulePermissionDefinition as M, type PermissionCheck as P, type PageUrl as a, type ModuleDefinition as b, type PermissionConfig as c, type PermissionModule as d, type PermissionUser as e, type ModuleWithPermissions as f, type ModuleFactory as g };
112
+ export { type ApiRequestDataTypeInterface as A, type FieldSelector as F, type GetterKeys as G, type ModuleWithPermissions as M, type PermissionCheck as P, Action as a, type PageUrl as b, createJsonApiInclusion as c, type ModulePermissionDefinition as d, type ModuleDefinition as e, type PermissionConfig as f, type PermissionModule as g, type PermissionUser as h, type ModuleFactory as i };
@@ -0,0 +1,39 @@
1
+ import { ColumnDef } from '@tanstack/react-table';
2
+ import { b as PageUrl } from './types-Bl61ob-7.mjs';
3
+ import { D as DataListRetriever } from './useDataListRetriever-futhx3OP.mjs';
4
+
5
+ type TableContent<T> = {
6
+ jsonApiData: T;
7
+ [key: string]: any;
8
+ };
9
+ interface TableStructureGeneratorInterface<T, U> {
10
+ generateTableStructure: (params: {
11
+ t: (key: string) => string;
12
+ generateUrl: (params: {
13
+ page: string | PageUrl | string;
14
+ id?: string;
15
+ }) => string;
16
+ data: T[];
17
+ fields: Array<U>;
18
+ checkedIds?: string[];
19
+ toggleId?: (id: string) => void;
20
+ }) => {
21
+ data: TableContent<T>[];
22
+ columns: ColumnDef<TableContent<T>>[];
23
+ };
24
+ }
25
+ type UseTableStructureHookParams<T, U> = {
26
+ data: T[];
27
+ fields: Array<U>;
28
+ checkedIds?: string[];
29
+ toggleId?: (id: string) => void;
30
+ dataRetriever?: DataListRetriever<T>;
31
+ context?: Record<string, any>;
32
+ };
33
+ type UseTableStructureHookReturn<T> = {
34
+ data: TableContent<T>[];
35
+ columns: ColumnDef<TableContent<T>>[];
36
+ };
37
+ type UseTableStructureHook<T, U> = (params: UseTableStructureHookParams<T, U>) => UseTableStructureHookReturn<T>;
38
+
39
+ export type { TableContent as T, UseTableStructureHook as U, UseTableStructureHookParams as a, UseTableStructureHookReturn as b, TableStructureGeneratorInterface as c };
@@ -0,0 +1,25 @@
1
+ import { N as NotificationInterface } from './notification.interface-BBgMUdLR.mjs';
2
+
3
+ interface UseSocketOptions {
4
+ token: string;
5
+ }
6
+ interface SocketLike {
7
+ emit: (event: string, ...args: any[]) => void;
8
+ on: (event: string, callback: (...args: any[]) => void) => void;
9
+ off: (event: string, callback?: (...args: any[]) => void) => void;
10
+ connected: boolean;
11
+ }
12
+ interface UseSocketReturn {
13
+ socket: SocketLike | null;
14
+ isConnected: boolean;
15
+ messages: any[];
16
+ socketNotifications: NotificationInterface[];
17
+ sendMessage: (event: string, data: any) => void;
18
+ removeMessage: (index: number) => void;
19
+ removeSocketNotification: (index: number) => void;
20
+ clearMessages: () => void;
21
+ clearSocketNotifications: () => void;
22
+ }
23
+ declare function useSocket({ token }: UseSocketOptions): UseSocketReturn;
24
+
25
+ export { useSocket as u };
@@ -0,0 +1,25 @@
1
+ import { N as NotificationInterface } from './notification.interface-gyvT-Z2F.js';
2
+
3
+ interface UseSocketOptions {
4
+ token: string;
5
+ }
6
+ interface SocketLike {
7
+ emit: (event: string, ...args: any[]) => void;
8
+ on: (event: string, callback: (...args: any[]) => void) => void;
9
+ off: (event: string, callback?: (...args: any[]) => void) => void;
10
+ connected: boolean;
11
+ }
12
+ interface UseSocketReturn {
13
+ socket: SocketLike | null;
14
+ isConnected: boolean;
15
+ messages: any[];
16
+ socketNotifications: NotificationInterface[];
17
+ sendMessage: (event: string, data: any) => void;
18
+ removeMessage: (index: number) => void;
19
+ removeSocketNotification: (index: number) => void;
20
+ clearMessages: () => void;
21
+ clearSocketNotifications: () => void;
22
+ }
23
+ declare function useSocket({ token }: UseSocketOptions): UseSocketReturn;
24
+
25
+ export { useSocket as u };
@@ -0,0 +1,18 @@
1
+ declare enum RoleFields {
2
+ roleId = "roleId",
3
+ name = "name",
4
+ description = "description",
5
+ createdAt = "createdAt",
6
+ updatedAt = "updatedAt"
7
+ }
8
+
9
+ declare enum UserFields {
10
+ userId = "userId",
11
+ name = "name",
12
+ email = "email",
13
+ relevance = "relevance",
14
+ createdAt = "createdAt",
15
+ updatedAt = "updatedAt"
16
+ }
17
+
18
+ export { RoleFields as R, UserFields as U };
@@ -0,0 +1,18 @@
1
+ declare enum RoleFields {
2
+ roleId = "roleId",
3
+ name = "name",
4
+ description = "description",
5
+ createdAt = "createdAt",
6
+ updatedAt = "updatedAt"
7
+ }
8
+
9
+ declare enum UserFields {
10
+ userId = "userId",
11
+ name = "name",
12
+ email = "email",
13
+ relevance = "relevance",
14
+ createdAt = "createdAt",
15
+ updatedAt = "updatedAt"
16
+ }
17
+
18
+ export { RoleFields as R, UserFields as U };
@@ -2,10 +2,9 @@ import { ClassValue } from 'clsx';
2
2
  export { ClassValue } from 'clsx';
3
3
  import * as React from 'react';
4
4
  import { ReactElement } from 'react';
5
- import { f as ModuleWithPermissions, A as Action } from '../types-lQVA8d_P.mjs';
5
+ import { M as ModuleWithPermissions, a as Action } from '../types-Bl61ob-7.mjs';
6
6
  import { z } from 'zod';
7
7
  import { PartialBlock } from '@blocknote/core';
8
- import '../ApiRequestDataTypeInterface-CUKFDBx2.mjs';
9
8
 
10
9
  declare function cn(...inputs: ClassValue[]): string;
11
10
 
@@ -2,10 +2,9 @@ import { ClassValue } from 'clsx';
2
2
  export { ClassValue } from 'clsx';
3
3
  import * as React from 'react';
4
4
  import { ReactElement } from 'react';
5
- import { f as ModuleWithPermissions, A as Action } from '../types-DluCaP1I.js';
5
+ import { M as ModuleWithPermissions, a as Action } from '../types-Bl61ob-7.js';
6
6
  import { z } from 'zod';
7
7
  import { PartialBlock } from '@blocknote/core';
8
- import '../ApiRequestDataTypeInterface-CUKFDBx2.js';
9
8
 
10
9
  declare function cn(...inputs: ClassValue[]): string;
11
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carlonicora/nextjs-jsonapi",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Next.js JSON:API client with server/client support and caching",
5
5
  "author": "Carlo Nicora",
6
6
  "license": "GPL-3.0-or-later",
@@ -8,7 +8,6 @@
8
8
  "main": "./dist/index.js",
9
9
  "module": "./dist/index.mjs",
10
10
  "types": "./dist/index.d.ts",
11
- "sideEffects": false,
12
11
  "exports": {
13
12
  ".": {
14
13
  "types": "./dist/index.d.ts",
@@ -120,6 +119,7 @@
120
119
  "@dnd-kit/core": "^6.3.1",
121
120
  "@dnd-kit/sortable": "^10.0.0",
122
121
  "@dnd-kit/utilities": "^3.2.2",
122
+ "@hookform/resolvers": "^5.2.2",
123
123
  "@radix-ui/react-accordion": "^1.2.12",
124
124
  "@radix-ui/react-alert-dialog": "^1.1.15",
125
125
  "@radix-ui/react-avatar": "^1.1.11",
@@ -147,7 +147,7 @@
147
147
  "class-variance-authority": "^0.7.1",
148
148
  "clsx": "^2.1.1",
149
149
  "cmdk": "^1.1.1",
150
- "cookies-next": "^6.0.0",
150
+ "cookies-next": "^6.1.1",
151
151
  "d3": "^7.9.0",
152
152
  "date-fns": "^4.1.0",
153
153
  "embla-carousel-react": "^8.6.0",
@@ -156,10 +156,12 @@
156
156
  "next-themes": "^0.4.6",
157
157
  "react-day-picker": "^9.11.3",
158
158
  "react-dropzone": "^14.3.8",
159
+ "react-hook-form": "^7.68.0",
159
160
  "react-markdown": "^10.1.0",
160
161
  "react-resizable-panels": "^3.0.6",
161
162
  "recharts": "^3.5.1",
162
163
  "remark-gfm": "^4.0.1",
164
+ "socket.io-client": "^4.8.1",
163
165
  "sonner": "^2.0.7",
164
166
  "tailwind-merge": "^3.4.0",
165
167
  "uuid": "^13.0.0",
@@ -9,3 +9,16 @@ export * from "./hooks";
9
9
  // Client-side request utilities
10
10
  export * from "./request";
11
11
  export * from "./token";
12
+
13
+ import { useCompanyTableStructure } from "../features/company/hooks";
14
+ // Table generator registration (must be in client-only context)
15
+ import { useRoleTableStructure } from "../features/role/hooks";
16
+ import { useUserTableStructure } from "../features/user/hooks";
17
+ import { registerTableGenerator } from "../hooks";
18
+
19
+ export * from "../features/role/hooks";
20
+ export * from "../features/user/hooks";
21
+
22
+ registerTableGenerator("roles", useRoleTableStructure);
23
+ registerTableGenerator("users", useUserTableStructure);
24
+ registerTableGenerator("companies", useCompanyTableStructure);
@@ -19,3 +19,4 @@ export * from "./FormSwitch";
19
19
  export * from "./FormTextarea";
20
20
  export * from "./MultiFileUploader";
21
21
  export * from "./PasswordInput";
22
+ export { FormFeatures } from "../../features/feature/components/forms/FormFeatures";
@@ -8,4 +8,9 @@ export * from "./navigations";
8
8
  export * from "./pages";
9
9
  export * from "./tables";
10
10
 
11
+ export * from "../features/auth/components";
12
+ export * from "../features/company/components";
13
+ export * from "../features/feature/components";
14
+ export * from "../features/notification/components";
15
+ export * from "../features/role/components";
11
16
  export * from "../features/user/components";
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import "../../client";
2
3
 
3
4
  import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
4
5
 
@@ -0,0 +1,52 @@
1
+ "use client";
2
+
3
+ import { useTranslations } from "next-intl";
4
+
5
+ import { createContext, ReactNode, useContext } from "react";
6
+ import { UserInterface } from "../features";
7
+ import { useCurrentUserContext } from "../features/user/contexts";
8
+ import { BreadcrumbItemData } from "../interfaces";
9
+ import { SharedProvider } from "./SharedContext";
10
+
11
+ interface CommonContextType {}
12
+
13
+ const CommonContext = createContext<CommonContextType | undefined>(undefined);
14
+
15
+ type CommonProviderProps = {
16
+ children: ReactNode;
17
+ };
18
+
19
+ export const CommonProvider = ({ children }: CommonProviderProps) => {
20
+ const { company } = useCurrentUserContext<UserInterface>();
21
+ const t = useTranslations();
22
+
23
+ const breadcrumb = () => {
24
+ const response: BreadcrumbItemData[] = [];
25
+
26
+ return response;
27
+ };
28
+
29
+ const title = () => {
30
+ const response: any = {
31
+ type: t(`generic.title`),
32
+ };
33
+
34
+ if (company) response.element = company.name;
35
+
36
+ return response;
37
+ };
38
+
39
+ return (
40
+ <SharedProvider value={{ breadcrumbs: breadcrumb(), title: title() }}>
41
+ <CommonContext.Provider value={{}}>{children}</CommonContext.Provider>
42
+ </SharedProvider>
43
+ );
44
+ };
45
+
46
+ export const useCommonContext = (): CommonContextType => {
47
+ const context = useContext(CommonContext);
48
+ if (context === undefined) {
49
+ throw new Error("useCommonContext must be used within a CommonProvider");
50
+ }
51
+ return context;
52
+ };
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  import { createContext, ReactNode, useContext } from "react";
2
4
  import { BreadcrumbItemData } from "../interfaces";
3
5
 
@@ -0,0 +1,65 @@
1
+ "use client";
2
+
3
+ import React, { createContext, useContext } from "react";
4
+ import { NotificationInterface } from "../features";
5
+ import { useSocket } from "../hooks";
6
+
7
+ interface SocketContextProps {
8
+ socket: ReturnType<typeof useSocket>["socket"];
9
+ isConnected: boolean;
10
+ messages: any[];
11
+ socketNotifications: NotificationInterface[];
12
+ sendMessage: (event: string, data: any) => void;
13
+ removeMessage: (index: number) => void;
14
+ removeSocketNotification: (index: number) => void;
15
+ clearMessages: () => void;
16
+ clearSocketNotifications: () => void;
17
+ }
18
+
19
+ const defaultContextValue: SocketContextProps = {
20
+ socket: null,
21
+ isConnected: false,
22
+ messages: [],
23
+ socketNotifications: [],
24
+ sendMessage: () => {},
25
+ removeMessage: () => {},
26
+ removeSocketNotification: () => {},
27
+ clearMessages: () => {},
28
+ clearSocketNotifications: () => {},
29
+ };
30
+
31
+ export const SocketContext = createContext<SocketContextProps>(defaultContextValue);
32
+
33
+ interface SocketProviderProps {
34
+ token?: string;
35
+ children: React.ReactNode;
36
+ }
37
+
38
+ export const SocketProvider: React.FC<SocketProviderProps> = ({ token, children }) => {
39
+ const socketHookData = token ? useSocket({ token }) : null;
40
+
41
+ const sendMessage = (event: string, data: any) => {
42
+ const currentSocket = socketHookData ? socketHookData.socket : defaultContextValue.socket;
43
+ const currentIsConnected = socketHookData ? socketHookData.isConnected : defaultContextValue.isConnected;
44
+
45
+ if (currentSocket && currentIsConnected) {
46
+ currentSocket.emit(event, data);
47
+ }
48
+ };
49
+
50
+ const value: SocketContextProps = {
51
+ ...defaultContextValue,
52
+ ...(socketHookData || {}),
53
+ sendMessage: sendMessage,
54
+ };
55
+
56
+ return <SocketContext.Provider value={value}>{children}</SocketContext.Provider>;
57
+ };
58
+
59
+ export const useSocketContext = () => {
60
+ const context = useContext(SocketContext);
61
+ if (!context) {
62
+ throw new Error("useSocketContext must be used within a SocketProvider");
63
+ }
64
+ return context;
65
+ };
@@ -1,2 +1,7 @@
1
+ export * from "../features/company/contexts/CompanyContext";
2
+ export * from "../features/notification/contexts/NotificationContext";
3
+ export * from "../features/role/contexts/RoleContext";
4
+ export * from "../features/user/contexts";
5
+ export * from "./CommonContext";
1
6
  export * from "./SharedContext";
2
- export * from "../features/user/contexts/CurrentUserContext";
7
+ export * from "./SocketContext";
@@ -0,0 +1,32 @@
1
+ "use client";
2
+
3
+ import Image from "next/image";
4
+ import { Card } from "../../../../shadcnui";
5
+ import { AuthContextProvider, useAuthContext } from "../../contexts";
6
+ import { AuthComponent } from "../../enums";
7
+
8
+ type AuthContainerProps = {
9
+ componentType: AuthComponent;
10
+ params?: { code?: string };
11
+ };
12
+
13
+ export function AuthContainer({ componentType, params }: AuthContainerProps) {
14
+ return (
15
+ <AuthContextProvider initialComponentType={componentType} initialParams={params}>
16
+ <InnerAuthContainer />
17
+ </AuthContextProvider>
18
+ );
19
+ }
20
+
21
+ function InnerAuthContainer() {
22
+ const { activeComponent } = useAuthContext();
23
+
24
+ if (activeComponent === null)
25
+ return (
26
+ <div className="max-w-sm">
27
+ <Image src="/phlow-logo.webp" alt="Phlow" width={100} height={100} className="animate-spin-slow" priority />
28
+ </div>
29
+ );
30
+
31
+ return <Card className="w-full max-w-md">{activeComponent}</Card>;
32
+ }
@@ -0,0 +1 @@
1
+ export * from "./AuthContainer";
@@ -0,0 +1,39 @@
1
+ "use client";
2
+
3
+ import { useTranslations } from "next-intl";
4
+ import Image from "next/image";
5
+ import { Button, CardDescription, CardFooter, CardHeader, CardTitle, Link } from "../../../../shadcnui";
6
+ import { useAuthContext } from "../../contexts";
7
+ import { AuthComponent } from "../../enums";
8
+
9
+ export function LandingComponent() {
10
+ const t = useTranslations();
11
+
12
+ const { setComponentType } = useAuthContext();
13
+
14
+ return (
15
+ <>
16
+ <CardHeader className="mb-4" data-testid="page-pre-login-container">
17
+ <CardTitle className="text-primary flex flex-col items-center gap-y-8 pb-8 text-4xl">
18
+ <Image src="/phlow-logo.webp" alt="Phlow" width={100} height={100} priority />
19
+ {t(`generic.title`)}
20
+ </CardTitle>
21
+ <CardDescription className="flex w-full justify-center text-center text-sm">
22
+ {t(`generic.description`)}
23
+ </CardDescription>
24
+ </CardHeader>
25
+ <CardFooter className="mt-4 flex w-full flex-col justify-between">
26
+ <Link href="#" className="flex w-full justify-start" onClick={() => setComponentType(AuthComponent.Register)}>
27
+ <Button className="mt-4 w-full" variant={`default`}>
28
+ {t(`foundations.auth.buttons.register`)}
29
+ </Button>
30
+ </Link>
31
+ <Link href="#" className="flex w-full justify-end" onClick={() => setComponentType(AuthComponent.Login)}>
32
+ <Button className="mt-4 w-full" variant={`outline`} data-testid="page-login-button-initial-login">
33
+ {t(`foundations.auth.buttons.login`)}
34
+ </Button>
35
+ </Link>
36
+ </CardFooter>
37
+ </>
38
+ );
39
+ }
@@ -0,0 +1 @@
1
+ export * from "./LandingComponent";