doc-nis-2 2.1.2 → 2.2.0

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 (114) hide show
  1. package/.env.example +47 -0
  2. package/README.md +185 -73
  3. package/db-migrations/20240112163555-init-down.sql +3 -0
  4. package/db-migrations/20240112163555-init-up.sql +47 -0
  5. package/db-migrations/20240209172146-elements-links-down.sql +3 -0
  6. package/db-migrations/20240209172146-elements-links-up.sql +65 -0
  7. package/db-migrations/20240220215714-createElement-down.sql +1 -0
  8. package/db-migrations/20240220215714-createElement-up.sql +19 -0
  9. package/db-migrations/20240221194852-createLink-down.sql +1 -0
  10. package/db-migrations/20240221194852-createLink-up.sql +21 -0
  11. package/db-migrations/20240223180214-getUpdatedData-down.sql +1 -0
  12. package/db-migrations/20240223180214-getUpdatedData-up.sql +17 -0
  13. package/db-migrations/20240307182656-createLayer-down.sql +1 -0
  14. package/db-migrations/20240307182656-createLayer-up.sql +18 -0
  15. package/db-migrations/20240426171507-inviteUser-down.sql +1 -0
  16. package/db-migrations/20240426171507-inviteUser-up.sql +33 -0
  17. package/db-migrations/20240429075201-createRight-down.sql +1 -0
  18. package/db-migrations/20240429075201-createRight-up.sql +18 -0
  19. package/db-migrations/20240704195520-history-down.sql +1 -0
  20. package/db-migrations/20240704195520-history-up.sql +30 -0
  21. package/db-migrations/20240731182807-fix-repository-update-down.sql +1 -0
  22. package/db-migrations/20240731182807-fix-repository-update-up.sql +26 -0
  23. package/db-migrations/20240808163906-repository-config-down.sql +1 -0
  24. package/db-migrations/20240808163906-repository-config-up.sql +2 -0
  25. package/db-migrations/20240921181309-new-rights-down.sql +1 -0
  26. package/db-migrations/20240921181309-new-rights-up.sql +34 -0
  27. package/db-migrations/20241224153527-immutable-links-down.sql +1 -0
  28. package/db-migrations/20241224153527-immutable-links-up.sql +79 -0
  29. package/db-migrations/20251003182530-createRepository-down.sql +1 -0
  30. package/db-migrations/20251003182530-createRepository-up.sql +15 -0
  31. package/db-migrations/20251010190500-utf8mb4-up.sql +22 -0
  32. package/db-migrations/20260116182200-getUpdatedData-down.sql +19 -0
  33. package/db-migrations/20260116182200-getUpdatedData-up.sql +19 -0
  34. package/db-migrations/20260301195700-inviteUser-down.sql +28 -0
  35. package/db-migrations/20260301195700-inviteUser-up.sql +28 -0
  36. package/dist-front/assets/QuoteElement-CFcdhavZ.js +1 -0
  37. package/dist-front/assets/QuoteLink-DSNoTf_G.js +1 -0
  38. package/dist-front/assets/advanced-search-by-IP-B2LqmXzp.png +0 -0
  39. package/dist-front/assets/advanced-search-by-IP-C6B-Mnn_.png +0 -0
  40. package/dist-front/assets/advanced-search-by-description-BQh6pwOz.png +0 -0
  41. package/dist-front/assets/advanced-search-by-description-DeuibbVB.png +0 -0
  42. package/dist-front/assets/advanced-search-by-url-DztVSGfW.png +0 -0
  43. package/dist-front/assets/advanced-search-by-url-RBKEve2P.png +0 -0
  44. package/dist-front/assets/advanced-search-with-prefix-CEOgevpn.png +0 -0
  45. package/dist-front/assets/advanced-search-with-prefix-Ck5N7mD9.png +0 -0
  46. package/dist-front/assets/cluster-B13UI1Nc.svg +38 -0
  47. package/dist-front/assets/dashboard-BONDdowW.png +0 -0
  48. package/dist-front/assets/dashboard-CCBJ1o4E.png +0 -0
  49. package/dist-front/assets/dashboard-open-repository-example-BNiZiPJz.png +0 -0
  50. package/dist-front/assets/dashboard-open-repository-example-DSfM0sX0.png +0 -0
  51. package/dist-front/assets/database-NzfpA0yk.svg +3 -0
  52. package/dist-front/assets/demo-L46EiYVv.svg +7 -0
  53. package/dist-front/assets/deployment-after-select-database-DiDyml4R.png +0 -0
  54. package/dist-front/assets/deployment-after-select-database-UPTEMfeH.png +0 -0
  55. package/dist-front/assets/deployment-before-filter-BEIB56RC.png +0 -0
  56. package/dist-front/assets/deployment-before-filter-DE1G-dz0.png +0 -0
  57. package/dist-front/assets/deployment-before-filter-hide-actors-obgFAPBN.png +0 -0
  58. package/dist-front/assets/deployment-before-filter-hide-actors-s3dqy1J1.png +0 -0
  59. package/dist-front/assets/deployment-diagram-select-elements-1-BNfG_zzE.png +0 -0
  60. package/dist-front/assets/deployment-diagram-select-elements-1-BkRHn1TY.png +0 -0
  61. package/dist-front/assets/deployment-diagram-select-elements-2-B8F5-nju.png +0 -0
  62. package/dist-front/assets/deployment-diagram-select-elements-2-BbE1fItW.png +0 -0
  63. package/dist-front/assets/deployment-diagram-select-elements-3-CiRgDAJx.png +0 -0
  64. package/dist-front/assets/deployment-diagram-select-elements-3-LyPiN4LO.png +0 -0
  65. package/dist-front/assets/deployment-diagram-select-elements-4-DgKXL6Sm.png +0 -0
  66. package/dist-front/assets/deployment-diagram-select-elements-4-Dl3zq3Es.png +0 -0
  67. package/dist-front/assets/deployment-diagram-select-elements-5-NYRRJYsK.png +0 -0
  68. package/dist-front/assets/deployment-diagram-select-elements-5-TfTB-Oqn.png +0 -0
  69. package/dist-front/assets/deployment-diagram-select-elements-6-BnmwzSpW.png +0 -0
  70. package/dist-front/assets/deployment-diagram-select-elements-6-SCgXRKlk.png +0 -0
  71. package/dist-front/assets/deployment-edit-element-name-BPdKcUZn.png +0 -0
  72. package/dist-front/assets/deployment-edit-element-name-BheWfdx2.png +0 -0
  73. package/dist-front/assets/diagram-without-test-layer-BhRiWpQ3.png +0 -0
  74. package/dist-front/assets/diagram-without-test-layer-D_RU0Xi1.png +0 -0
  75. package/dist-front/assets/ebios-study-Bho5n-GV.svg +32 -0
  76. package/dist-front/assets/element-list-not-filtered-Cvk8tB2f.png +0 -0
  77. package/dist-front/assets/element-list-not-filtered-XVyTUoxe.png +0 -0
  78. package/dist-front/assets/element-list-search-1-DOle2VkK.png +0 -0
  79. package/dist-front/assets/element-list-search-1-DPOY58Eg.png +0 -0
  80. package/dist-front/assets/element-list-search-2-CpcGE9_3.png +0 -0
  81. package/dist-front/assets/element-list-search-2-Dix_xXBI.png +0 -0
  82. package/dist-front/assets/element-list-search-3-BFiRuPza.png +0 -0
  83. package/dist-front/assets/element-list-search-3-E4XtlyZR.png +0 -0
  84. package/dist-front/assets/empty-diagram-BM1L95vH.png +0 -0
  85. package/dist-front/assets/empty-diagram-DhYDVI3_.png +0 -0
  86. package/dist-front/assets/en-DuVXZVVZ.svg +49 -0
  87. package/dist-front/assets/feared-DX2kKwEr.svg +95 -0
  88. package/dist-front/assets/flUhRq6tzZclQEJ-Vdg-IuiaDsNa-Dr0goTwe.woff +0 -0
  89. package/dist-front/assets/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ-D-x-0Q06.woff2 +0 -0
  90. package/dist-front/assets/fr-3MnKmuj-.svg +67 -0
  91. package/dist-front/assets/handshake-CLBgN385.svg +7 -0
  92. package/dist-front/assets/home-page-B7fHs2kb.png +0 -0
  93. package/dist-front/assets/home-page-Ck94L7Rl.png +0 -0
  94. package/dist-front/assets/index-Bv4Dk-O8.js +515 -0
  95. package/dist-front/assets/index-CgPoNf8Z.css +1 -0
  96. package/dist-front/assets/login-page-BIToVvfp.png +0 -0
  97. package/dist-front/assets/login-page-emYnvcIi.png +0 -0
  98. package/dist-front/assets/operationalScenarioIconUrl-DZ8l0Nn6.svg +7 -0
  99. package/dist-front/assets/plantuml-svgrepo-com-BIVF1_vn.svg +2 -0
  100. package/dist-front/assets/report-Cv0X9yu-.svg +64 -0
  101. package/dist-front/assets/repository-home-page-D_F5-WZx.png +0 -0
  102. package/dist-front/assets/repository-home-page-KykG8Rih.png +0 -0
  103. package/dist-front/assets/risk-icon-Bfk9Grgo.svg +7 -0
  104. package/dist-front/assets/select-diagrams-elements-CSBEk5Cr.png +0 -0
  105. package/dist-front/assets/select-diagrams-elements-C_VbqYVh.png +0 -0
  106. package/dist-front/assets/sla-C7BILuuV.svg +20 -0
  107. package/dist-front/assets/techno-icon-BoBtMTDP.svg +53 -0
  108. package/dist-front/favicon.ico +0 -0
  109. package/dist-front/images/clean-it.jpg +0 -0
  110. package/dist-front/images/collaboration.png +0 -0
  111. package/dist-front/index.html +12 -0
  112. package/package.json +37 -88
  113. package/plantuml/plantuml-1.2025.4.jar +0 -0
  114. package/src/doc-nis-2.js +89768 -0
package/.env.example ADDED
@@ -0,0 +1,47 @@
1
+ # APP
2
+ NODE_ENV = "test" # or "dev" "prod"
3
+ URL = 'https://demo.doc-nis-2.com' # if you are behind a reverse proxy, specify the external URL
4
+ PORT = 4000
5
+
6
+ PLANTUML_SERVER = 'http://127.0.0.1:8080' # in order to serve the /plantuml route. ideally should be served by the reverse proxy
7
+
8
+ #CONFIG BDD DOC_IT
9
+ DB_DOC_IT_HOST = "127.0.0.1"
10
+ DB_DOC_IT_USER = "root"
11
+ DB_DOC_IT_PORT = 3306
12
+ DB_DOC_IT_PASSWORD = "mysqlroot"
13
+ DB_DOC_IT_NAME = "doc_nis_2_test"
14
+ BD_DOC_IT_CONNECTION_LIMIT = 20
15
+
16
+ # migration system 0=only ckeck 1= do Migrations if needed
17
+ DO_MIGRATIONS = 0
18
+
19
+ # AUTHENTIFICATION GOOGLE
20
+ GOOGLE_CLIENT_ID = ""
21
+ GOOGLE_CLIENT_SECRET = ""
22
+
23
+ # CREATION TOKEN
24
+ JWT_SECRET = # PUT HERE your own random value should be at least 32 char long ideally created with a password generator
25
+ JWT_EXPIRES_IN = 86400000
26
+ TWT_PASSWORD_RESET_EXPIRES_IN = 600000
27
+
28
+ # MAIL FOR FORGET MY PASSWORD
29
+ ADMIN_MAIL =
30
+ ADMIN_MAIL_PASSWORD =
31
+ ADMIN_MAIL_SMTP =
32
+ ADMIN_MAIL_PORT =
33
+ ADMIN_MAIL_REQUIRE_TLS = # 1= force using TLS 0 by default
34
+
35
+ # LOGGER
36
+ LOGGER_LEVEL = "debug" # "trace" to track a problem, "info for production"
37
+
38
+ # UPLOADS
39
+ UPLOADS = # a path where to store document uploads
40
+
41
+ # FEATURES
42
+ ## ONBOARDING new Users 1=new users can selt create an account and a repository
43
+ ## 0=users have to be invited by an existing user that has the rights
44
+ ONBOARDING = 0
45
+
46
+ ## DO_MIGRATIONS = 1 will migrate if needed; 0 = only check if all migrations are done
47
+ DO_MIGRATIONS = 1
package/README.md CHANGED
@@ -1,73 +1,185 @@
1
- # Doc-NIS-2
2
-
3
- the [NIS-2 directive](https://eur-lex.europa.eu/EN/legal-content/summary/cybersecurity-of-network-and-information-systems.html)
4
- will force thousands of companies accross Europe to become more resillient on cyber threats
5
-
6
- For many of those meddium size buisnesses this is both a treat and an opportunity
7
- * a threat because they are not used to have a proper documentation (if any exists outside of the heads of the people)
8
- * creating such a documentation is a real challenge
9
- * existing tools are
10
- 1) very expensive
11
- 2) intended for larger organisations
12
- 3) have a steep learning curve, needing often a dedicated team
13
- * an opportunity because eventually not only they will be more resillient, but also will bet a better
14
- understanding of their Information System
15
-
16
- with that in mind `Doc-NIS-2` is born after beeing fully rewritten from a private tool made during the COVID in order to help
17
- a company
18
-
19
- The main goals of `Doc-NIS-2` are
20
- * document an Information System
21
- * document the major processes of a company and describe the applications supporting thoses processes
22
- * document the risks using [EBOIS](https://cyber.gouv.fr/en/publications/ebios-risk-manager-method)
23
- * **user friendly**, **minimum of effort** and **collaborative**
24
- * **open source**
25
-
26
- The main principles are
27
- * every **element** of the system (actors, applications, servers, clouds, processes...) are described in a database
28
- * every **link** between thoses elements (an application uses another application... ) are also described
29
- * partial graphs are **automatically** created and represented using [plantuml](https://plantuml.com/). All graphs are enhanced in order to make them interactive.
30
- * all users can **collaborate** at the same time, each user having rights on each class of element
31
-
32
- ![](./_front/user-docs/en/screenshots/deployment-edit-element-name.png)
33
-
34
-
35
- ## installation
36
-
37
- `Doc-NIS-2` is a web application written in [Vue](https://vuejs.org/) for the front and [node](https://nodejs.org/) for the back
38
-
39
- It needs a [mariadb](https://mariadb.com/docs) for the database
40
-
41
- So it can be deployed easily on Linux or Windows
42
-
43
- ### install mariadb
44
- if needed, install mariadb. the community version is fully ok for this application
45
-
46
- #### create database
47
-
48
- create as many database that you need `doc_nis_2_prod` (and if you want a test environnement `doc_nis_2_test`)
49
-
50
-
51
- #### user for the migrations
52
-
53
- In order to create the database (and for future migrations) we need to have a user that has
54
- higher rights than in production in order to create the schema. This user must at least have
55
-
56
- ```sql
57
- SHOW GRANTS FOR 'doc-nis-2-migrate'@'localhost'
58
- ```
59
- | Grants for doc-nis-2-migrate@localhost |
60
- | --- |
61
- | GRANT USAGE ON *.* TO `doc-nis-2-migrate`@`localhost` IDENTIFIED BY PASSWORD '*566B7C98855895F9B303B58D292E191D03B8FFF8' |
62
- | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, EXECUTE, CREATE VIEW, CREATE ROUTINE, ALTER ROUTINE, TRIGGER ON `doc\_it2\_dev`.* TO `doc-nis-2-migrate`@`localhost` |
63
-
64
- #### user for production
65
- ```sql
66
- SHOW GRANTS FOR 'doc-nis-2'@'localhost'
67
-
68
- ```
69
- | Grants for doc-nis-2@localhost |
70
- | --- |
71
- | GRANT USAGE ON *.* TO `doc-nis-2`@`localhost` IDENTIFIED BY PASSWORD '*A8B2ACD89C87A533D5077B928E8AF0BC87ED4FF4' |
72
- | GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `doc\_it2\_dev`.* TO `doc-nis-2`@`localhost` |
73
-
1
+ <div align="center">
2
+ <img alt="latest" aria-hidden="" class="project-badge" src="https://gitlab.com/nicole_innovation/doc-nis-2/-/badges/release.svg">
3
+ <img alt="coverage" aria-hidden="" class="project-badge" src="https://gitlab.com/nicole_innovation/doc-nis-2/badges/master/coverage.svg">
4
+ </div>
5
+
6
+ # Doc-NIS-2
7
+
8
+ the [NIS-2 directive](https://eur-lex.europa.eu/EN/legal-content/summary/cybersecurity-of-network-and-information-systems.html)
9
+ will force thousands of companies accross Europe to become more resillient on cyber threats
10
+
11
+ For many of those meddium size buisnesses this is both a treat and an opportunity
12
+ * a threat because they are not used to have a proper documentation (if any exists outside of the heads of the people)
13
+ * creating such a documentation is a real challenge
14
+ * existing tools are
15
+ 1) very expensive
16
+ 2) intended for larger organisations
17
+ 3) have a steep learning curve, needing often a dedicated team
18
+ * an opportunity because eventually not only they will be more resillient, but also will bet a better
19
+ understanding of their Information System
20
+
21
+ with that in mind `Doc-NIS-2` is born after beeing fully rewritten from a private tool made during the COVID in order to help
22
+ a company
23
+
24
+ The main goals of `Doc-NIS-2` are
25
+ * document an Information System
26
+ * document the major processes of a company and describe the applications supporting thoses processes
27
+ * document the risks using [EBOIS](https://cyber.gouv.fr/en/publications/ebios-risk-manager-method)
28
+ * **user friendly**, **minimum of effort** and **collaborative**
29
+ * **open source**
30
+
31
+ The main principles are
32
+ * every **element** of the system (actors, applications, servers, clouds, processes...) are described in a database
33
+ * every **link** between thoses elements (an application uses another application... ) are also described
34
+ * partial graphs are **automatically** created and represented using [plantuml](https://plantuml.com/). All graphs are enhanced in order to make them interactive.
35
+ * all users can **collaborate** at the same time, each user having rights on each class of element
36
+
37
+ ![](./_front/user-docs/en/screenshots/deployment-edit-element-name.png)
38
+
39
+
40
+
41
+ ## installation
42
+
43
+ the simplified installation is the following
44
+ ```plantuml
45
+ @startuml
46
+ actor user
47
+ [browser]
48
+ [doc-nis-2]
49
+ database mariadb
50
+ user --> browser
51
+ [browser] --> [doc-nis-2]
52
+ [doc-nis-2] --> mariadb
53
+ [doc-nis-2] --> [plantuml]
54
+ @enduml
55
+ ```
56
+
57
+ `Doc-NIS-2` is a web application written in [Vue](https://vuejs.org/) for the front and [node](https://nodejs.org/) for the back
58
+
59
+ It needs a [mariadb](https://mariadb.com/docs) for the database
60
+
61
+ So it can be deployed easily on Linux or Windows
62
+
63
+ ### install mariadb
64
+ if needed, [install mariadb](https://mariadb.com/downloads/?utm_source=header&utm_medium=website). the community version is fully ok for this application. It has been tested with `11.8.5` and `10.11.15`
65
+
66
+ #### create database
67
+
68
+ create as many database that you need `doc_nis_2_prod` (and if you want a test environnement `doc_nis_2_test`).
69
+ Just create an empty database. The migration system of doc-nis-2 will do the rest
70
+
71
+
72
+ #### user for the migrations
73
+
74
+ In order to create the database (and for future migrations) we need to have a user that has
75
+ higher rights than in production in order to create the schema. This user must at least have
76
+
77
+ ```sql
78
+ SHOW GRANTS FOR 'doc-nis-2-migrate'@'localhost'
79
+ ```
80
+ | Grants for doc-nis-2-migrate@localhost |
81
+ | --- |
82
+ | GRANT USAGE ON *.* TO `doc-nis-2-migrate`@`localhost` IDENTIFIED BY PASSWORD '*566B7C98855895F9B303B58D292E191D03B8FFF8' |
83
+ | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, EXECUTE, CREATE VIEW, CREATE ROUTINE, ALTER ROUTINE, TRIGGER ON `doc\_it2\_dev`.* TO `doc-nis-2-migrate`@`localhost` |
84
+
85
+ #### user for production
86
+ ```sql
87
+ SHOW GRANTS FOR 'doc-nis-2'@'localhost'
88
+
89
+ ```
90
+ | Grants for doc-nis-2@localhost |
91
+ | --- |
92
+ | GRANT USAGE ON *.* TO `doc-nis-2`@`localhost` IDENTIFIED BY PASSWORD '*A8B2ACD89C87A533D5077B928E8AF0BC87ED4FF4' |
93
+ | GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `doc\_it2\_dev`.* TO `doc-nis-2`@`localhost` |
94
+
95
+ ### install node
96
+
97
+ we use node `25.8.2` but should be of with node > `20`
98
+
99
+ ### install doc-nis-2
100
+
101
+ create a new folder where you want doc-nis-2 to be installed
102
+
103
+ ```bash
104
+ npm install doc-nis-2
105
+ ```
106
+
107
+ ### create a .env file
108
+
109
+ the file must be `.env.dev` for the dev environnement (default), `.env.prod` for the prod env etc..
110
+
111
+ **example of .env.test**
112
+
113
+ ```ini
114
+ # APP
115
+ NODE_ENV = "test" # or "dev" "prod"
116
+ URL = 'http://localhost' # if you are behind a reverse proxy, specify the external URL
117
+ PORT = 4000
118
+
119
+ PLANTUML_SERVER = 'http://127.0.0.1:8080' # in order to serve the /plantuml route. ideally should be served by the reverse proxy
120
+
121
+ #CONFIG BDD DOC_IT
122
+ DB_DOC_IT_HOST = "127.0.0.1"
123
+ DB_DOC_IT_USER = "doc-nis-2-migrate"
124
+ DB_DOC_IT_PORT = 3306
125
+ DB_DOC_IT_PASSWORD = "xxxxxx"
126
+ DB_DOC_IT_NAME = "doc_nis_2_test"
127
+ BD_DOC_IT_CONNECTION_LIMIT = 20
128
+
129
+ # migration system 0=only ckeck; 1=do Migrations if needed
130
+ DO_MIGRATIONS = 1
131
+
132
+ # CREATION TOKEN
133
+ JWT_SECRET = # PUT HERE your own random value should be at least 32 char long ideally created with a password generator
134
+ JWT_EXPIRES_IN = 86400000
135
+ TWT_PASSWORD_RESET_EXPIRES_IN = 600000
136
+
137
+ # MAIL FOR FORGET MY PASSWORD
138
+ ADMIN_MAIL =
139
+ ADMIN_MAIL_PASSWORD =
140
+ ADMIN_MAIL_SMTP =
141
+ ADMIN_MAIL_PORT =
142
+ ADMIN_MAIL_REQUIRE_TLS = 1 # 1= force using TLS 0 by default
143
+
144
+ # LOGGER
145
+ LOGGER_LEVEL = "debug" # "trace" to track a problem, "info for production"
146
+
147
+ # UPLOADS
148
+ UPLOADS = # a path where to store document uploads
149
+
150
+ # FEATURES
151
+ ## ONBOARDING new Users 1=new users can self create an account and a repository
152
+ ## 0=users have to be invited by an existing user that has the rights
153
+ ONBOARDING = 0
154
+
155
+ ## DO_MIGRATIONS = 1 will migrate if needed; 0 = only check if all migrations are done
156
+ DO_MIGRATIONS = 1
157
+ ```
158
+
159
+ at the beginning use the `doc-nis-2-migrate` user as it will have to apply all migrations.
160
+
161
+ For a demontrator, this is fine to play with that user, but in production this is safer to use
162
+ a more restricted user in order to increase safety.
163
+
164
+ ### install plantuml
165
+
166
+ doc-nis-2 package comes with the last version that has been tested. It is unsafe to use https://plantuml.com since it can change without notice
167
+ and doc-nis-2 expect given pattern in order to highlight the graphs.
168
+
169
+ plantuml needs java, so please [install java](https://www.oracle.com/java/technologies/) first
170
+
171
+ ## lauch
172
+
173
+ open a first terminal and lauch plantuml
174
+ ```bash
175
+ java -DPLANTUML_LIMIT_SIZE=8192 -jar ./node_modules/doc-nis-2/plantuml/plantuml-1.2025.4.jar -picoweb
176
+ ```
177
+
178
+ in a separate terminal, lauch
179
+ ```bash
180
+ NODE_ENV=test npx doc-nis-2
181
+ ```
182
+ NODE_ENV=xxx sets the env
183
+
184
+
185
+
@@ -0,0 +1,3 @@
1
+ DROP TABLE `rights`;
2
+ DROP TABLE `users`;
3
+ DROP TABLE `repositories`;
@@ -0,0 +1,47 @@
1
+ /* initial creation of the database */
2
+
3
+ CREATE TABLE `repositories` (
4
+ `id` INT(11) NOT NULL AUTO_INCREMENT,
5
+ `name` VARCHAR(50) NOT NULL,
6
+ `createdAt` DATETIME NOT NULL DEFAULT NOW(),
7
+ `updatedAt` DATETIME NOT NULL DEFAULT NOW() ON UPDATE NOW(),
8
+ `deleted` TINYINT NOT NULL DEFAULT 0,
9
+ PRIMARY KEY (`id`) USING BTREE,
10
+ UNIQUE INDEX `name_UNIQUE` (`name`) USING BTREE
11
+ )
12
+ COMMENT='a repository is likely to be a company. An repository is isolated from another repository.\r\nMost tables have a FK on repId. \r\nusers can have rights on multiples repositories'
13
+ COLLATE='utf8_general_ci';
14
+
15
+ CREATE TABLE `users` (
16
+ `id` INT(11) NOT NULL AUTO_INCREMENT,
17
+ `name` VARCHAR(50) NOT NULL,
18
+ `firstname` VARCHAR(50) NOT NULL,
19
+ `email` VARCHAR(50) NOT NULL,
20
+ `password` VARCHAR(200) NOT NULL,
21
+ `role` VARCHAR(15) NULL DEFAULT NULL,
22
+ `deleted` TINYINT(1) NULL DEFAULT 0,
23
+ `createdAt` DATETIME NULL DEFAULT NOW(),
24
+ `updatedAt` DATETIME NULL DEFAULT NOW() ON UPDATE NOW(),
25
+ PRIMARY KEY (`id`) USING BTREE,
26
+ UNIQUE INDEX `email_UNIQUE` (`email`) USING BTREE
27
+ )
28
+ COMMENT='a user should be a real person. He can be either admin or has specific rights'
29
+ COLLATE='utf8mb4_general_ci';
30
+
31
+ CREATE TABLE `rights` (
32
+ `id` INT(11) NOT NULL AUTO_INCREMENT,
33
+ `userId` INT(11) NOT NULL,
34
+ `repId` INT(11) NOT NULL,
35
+ `moduleId` INT(11) NOT NULL,
36
+ `permission` INT(11) NULL DEFAULT NULL,
37
+ `deleted` TINYINT NOT NULL DEFAULT 0,
38
+ `createdAt` DATETIME NOT NULL DEFAULT NOW(),
39
+ `updatedAt` DATETIME NOT NULL DEFAULT NOW() ON UPDATE NOW(),
40
+ PRIMARY KEY (`id`) USING BTREE,
41
+ CONSTRAINT `FK_right_user` FOREIGN KEY (`userId`) REFERENCES `users` (`id`),
42
+ CONSTRAINT `FK_right_env` FOREIGN KEY (`repId`) REFERENCES `repositories` (`id`)
43
+ )
44
+ COMMENT='a right is for a user in a repository, what he can do on a module'
45
+ COLLATE='utf8mb4_general_ci';
46
+
47
+
@@ -0,0 +1,3 @@
1
+ DROP TABLE `links`;
2
+ DROP TABLE `elements`;
3
+ DROP TABLE `layers`;
@@ -0,0 +1,65 @@
1
+
2
+ CREATE TABLE `layers` (
3
+ `id` INT NOT NULL AUTO_INCREMENT,
4
+ `name` VARCHAR(255) NOT NULL,
5
+ `repId` INT NULL DEFAULT NULL,
6
+ `color` VARCHAR(20) NOT NULL,
7
+ `mdDescription` MEDIUMTEXT NOT NULL DEFAULT '',
8
+ `fields` JSON NULL DEFAULT NULL,
9
+ `deleted` TINYINT NOT NULL DEFAULT 0,
10
+ `createdAt` DATETIME NOT NULL DEFAULT current_timestamp(),
11
+ `updatedAt` DATETIME NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
12
+ PRIMARY KEY (`id`) USING BTREE,
13
+ INDEX `FK_layer_rep` (`repId`) USING BTREE,
14
+ CONSTRAINT `FK_layer_rep` FOREIGN KEY (`repId`) REFERENCES `repositories` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
15
+ )
16
+ COLLATE='utf8_general_ci'
17
+ ;
18
+
19
+
20
+ CREATE TABLE `elements` (
21
+ `id` INT NOT NULL AUTO_INCREMENT,
22
+ `name` VARCHAR(255) NOT NULL DEFAULT '',
23
+ `repId` INT NULL DEFAULT NULL,
24
+ `layerId` INT NULL DEFAULT NULL,
25
+ `className` VARCHAR(20) NOT NULL,
26
+ `mdDescription` MEDIUMTEXT NOT NULL DEFAULT '',
27
+ `fields` JSON NULL DEFAULT NULL,
28
+ `deleted` TINYINT NOT NULL DEFAULT 0,
29
+ `createdAt` DATETIME NOT NULL DEFAULT current_timestamp(),
30
+ `updatedAt` DATETIME NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
31
+ PRIMARY KEY (`id`) USING BTREE,
32
+ INDEX `FK_element_rep` (`repId`) USING BTREE,
33
+ CONSTRAINT `FK_element_rep` FOREIGN KEY (`repId`) REFERENCES `repositories` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
34
+
35
+ INDEX `FK_element_layer` (`layerId`) USING BTREE,
36
+ CONSTRAINT `FK_element_layer` FOREIGN KEY (`layerId`) REFERENCES .`layers` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
37
+ )
38
+ COLLATE='utf8_general_ci'
39
+ ;
40
+
41
+ CREATE TABLE `links` (
42
+ `id` INT NOT NULL AUTO_INCREMENT,
43
+ `name` VARCHAR(255) NOT NULL DEFAULT '',
44
+ `sourceId` INT NOT NULL,
45
+ `destId` INT NOT NULL,
46
+ `repId` INT NULL DEFAULT NULL,
47
+ `className` VARCHAR(20) NOT NULL,
48
+ `mdDescription` MEDIUMTEXT NOT NULL DEFAULT '',
49
+ `fields` JSON NULL DEFAULT NULL,
50
+ `dir` TINYINT NOT NULL DEFAULT 0,
51
+ `deleted` TINYINT NOT NULL DEFAULT 0,
52
+ `createdAt` DATETIME NOT NULL DEFAULT current_timestamp(),
53
+ `updatedAt` DATETIME NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
54
+ PRIMARY KEY (`id`) USING BTREE,
55
+ INDEX `FK_link_rep` (`repId`) USING BTREE,
56
+ CONSTRAINT `FK_link_rep` FOREIGN KEY (`repId`) REFERENCES `repositories` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
57
+
58
+ INDEX `FK_source_element` (`sourceId`) USING BTREE,
59
+ CONSTRAINT `FK_source_element` FOREIGN KEY (`sourceId`) REFERENCES `elements` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
60
+
61
+ INDEX `FK_dest_element` (`destId`) USING BTREE,
62
+ CONSTRAINT `FK_dest_element` FOREIGN KEY (`destId`) REFERENCES `elements` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
63
+ )
64
+ COLLATE='utf8_general_ci'
65
+ ;
@@ -0,0 +1 @@
1
+ DROP PROCEDURE `createElement`
@@ -0,0 +1,19 @@
1
+ CREATE PROCEDURE `createElement`(
2
+ IN `p_name` VARCHAR(255),
3
+ IN `p_repId` INT,
4
+ IN `p_layerId` INT,
5
+ IN `p_className` VARCHAR(20),
6
+ IN `p_mdDescription` MEDIUMTEXT,
7
+ IN `p_fields` JSON
8
+ )
9
+ LANGUAGE SQL
10
+ NOT DETERMINISTIC
11
+ CONTAINS SQL
12
+ SQL SECURITY DEFINER
13
+ COMMENT ''
14
+ BEGIN
15
+ INSERT INTO elements
16
+ (`name`,`repId`,`layerId`,`className`,`mdDescription`,`fields`) VALUES
17
+ (p_name,p_repId,p_layerId,p_className,p_mdDescription,p_fields);
18
+ SELECT * FROM elements WHERE id = LAST_INSERT_ID();
19
+ END
@@ -0,0 +1 @@
1
+ DROP PROCEDURE createLink
@@ -0,0 +1,21 @@
1
+ CREATE PROCEDURE `createLink`(
2
+ IN `p_name` VARCHAR(255),
3
+ IN `p_sourceId` INT,
4
+ IN `p_destId` INT,
5
+ IN `p_repId` INT,
6
+ IN `p_className` VARCHAR(20),
7
+ IN `p_mdDescription` MEDIUMTEXT,
8
+ IN `p_fields` JSON,
9
+ IN `p_dir` TINYINT
10
+ )
11
+ LANGUAGE SQL
12
+ NOT DETERMINISTIC
13
+ CONTAINS SQL
14
+ SQL SECURITY DEFINER
15
+ COMMENT ''
16
+ BEGIN
17
+ INSERT INTO links
18
+ (`name`,`sourceId`,`destId`,`repId`,`className`,`mdDescription`,`fields`,`dir`) VALUES
19
+ (p_name,p_sourceId,p_destId,p_repId,p_className,p_mdDescription,p_fields,p_dir);
20
+ SELECT * FROM links WHERE id = LAST_INSERT_ID();
21
+ END
@@ -0,0 +1 @@
1
+ DROP PROCEDURE `getUpdatedData`;
@@ -0,0 +1,17 @@
1
+ CREATE PROCEDURE `getUpdatedData`(
2
+ IN `p_repId` INT,
3
+ IN `p_since` DATETIME
4
+ )
5
+ LANGUAGE SQL
6
+ NOT DETERMINISTIC
7
+ CONTAINS SQL
8
+ SQL SECURITY DEFINER
9
+ COMMENT ''
10
+ BEGIN
11
+ DECLARE lastUpdate DATETIME DEFAULT NOW();
12
+ SELECT lastUpdate;
13
+ SELECT * FROM repositories WHERE id = p_repId;
14
+ SELECT * FROM elements WHERE repId = p_repId AND updatedAt BETWEEN p_since AND lastUpdate;
15
+ SELECT * FROM links WHERE repId = p_repId AND updatedAt BETWEEN p_since AND lastUpdate;
16
+ SELECT * FROM layers WHERE repId = p_repId AND updatedAt BETWEEN p_since AND lastUpdate;
17
+ END
@@ -0,0 +1 @@
1
+ DROP PROCEDURE createLayer;
@@ -0,0 +1,18 @@
1
+ CREATE PROCEDURE `createLayer`(
2
+ IN `p_name` VARCHAR(255),
3
+ IN `p_repId` INT,
4
+ IN `p_color` VARCHAR(20),
5
+ IN `p_mdDescription` MEDIUMTEXT,
6
+ IN `p_fields` JSON
7
+ )
8
+ LANGUAGE SQL
9
+ NOT DETERMINISTIC
10
+ CONTAINS SQL
11
+ SQL SECURITY DEFINER
12
+ COMMENT 'create a new layer and return it as result'
13
+ BEGIN
14
+ INSERT INTO layers
15
+ (`name`,`repId`,`color`,`mdDescription`) VALUES
16
+ (p_name,p_repId,p_color,p_mdDescription);
17
+ SELECT * FROM layers WHERE id = LAST_INSERT_ID();
18
+ END
@@ -0,0 +1 @@
1
+ DROP PROCEDURE `inviteUser`
@@ -0,0 +1,33 @@
1
+ CREATE PROCEDURE `inviteUser`(
2
+ IN `p_email` VARCHAR(255),
3
+ IN `p_repId` INT
4
+ )
5
+ LANGUAGE SQL
6
+ NOT DETERMINISTIC
7
+ CONTAINS SQL
8
+ SQL SECURITY DEFINER
9
+ COMMENT 'invite a user to a repository (and create it if the email is not existing); set a read right to the repository'
10
+
11
+
12
+ BEGIN
13
+ DECLARE v_userId INT DEFAULT 0;
14
+ DECLARE v_rightId INT DEFAULT 0;
15
+ DECLARE v_permission INT DEFAULT 0;
16
+
17
+ SELECT id INTO v_userId FROM users WHERE email = p_email;
18
+ IF v_userId = 0 THEN
19
+ INSERT INTO users
20
+ (`name`,`firstname`,`email`,`password`, `role`) VALUES
21
+ ('', '', p_email,' Password not initialized ','user'); -- password is unvalid since not 60 chars ==> no password can match this "hash"
22
+ SET v_userId = LAST_INSERT_ID();
23
+ END IF;
24
+
25
+ -- look for existing right for REPOSITORY
26
+ SELECT id INTO v_rightId FROM rights WHERE userId = v_userId AND repId = p_repId AND moduleId = 2;
27
+
28
+ IF v_rightId = 0 THEN
29
+ INSERT INTO rights (userId,repId,moduleId,permission) VALUES (v_userId,p_repId,2,1); -- read permission
30
+ END IF;
31
+
32
+ SELECT `id`,`name`,`firstname`,`email`,`role`,`deleted`,`createdAt`,`updatedAt` FROM users WHERE id = v_userId;
33
+ END
@@ -0,0 +1 @@
1
+ DROP PROCEDURE `createRight`;
@@ -0,0 +1,18 @@
1
+ CREATE PROCEDURE `createRight`(
2
+ IN `p_userId` INT,
3
+ IN `p_repId` INT,
4
+ IN `p_moduleId` INT,
5
+ IN `p_permission` INT
6
+ )
7
+ LANGUAGE SQL
8
+ NOT DETERMINISTIC
9
+ CONTAINS SQL
10
+ SQL SECURITY DEFINER
11
+ COMMENT 'create a new right and return it as result'
12
+ BEGIN
13
+ INSERT INTO rights
14
+ (userId,repId,moduleId,permission)
15
+ VALUES
16
+ (p_userId,p_repId,p_moduleId,p_permission);
17
+ SELECT * FROM rights WHERE id = LAST_INSERT_ID();
18
+ END
@@ -0,0 +1 @@
1
+ DROP TABLE history;
@@ -0,0 +1,30 @@
1
+ CREATE TABLE `history` (
2
+ `id` INT NOT NULL AUTO_INCREMENT,
3
+ `createdAt` DATETIME NOT NULL DEFAULT NOW(),
4
+ `updatedAt` DATETIME NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
5
+ `userId` INT NOT NULL,
6
+ `operation` INT NOT NULL COMMENT '0=update element 1=comment element 100=update link ',
7
+ `data` JSON NULL DEFAULT NULL,
8
+ `repId` INT AS (JSON_VALUE(`data`,'$.repId')) VIRTUAL,
9
+ `elementId` INT AS (CASE WHEN `operation` <100 THEN JSON_VALUE(`data`,'$.id') ELSE NULL END) VIRTUAL,
10
+ `linkId` INT AS (CASE `operation` WHEN 100 THEN JSON_VALUE(`data`,'$.id') ELSE NULL END) VIRTUAL,
11
+ `sourceId` INT AS (JSON_VALUE(`data`,'$.sourceId')) VIRTUAL,
12
+ `destId` INT AS (JSON_VALUE(`data`,'$.destId')) VIRTUAL,
13
+ PRIMARY KEY (`id`),
14
+ INDEX `IDX_createdAt` (`createdAt`),
15
+ CONSTRAINT `FK__users` FOREIGN KEY (`userId`) REFERENCES `users` (`id`),
16
+ CONSTRAINT `FK__elements` FOREIGN KEY (`elementId`) REFERENCES `elements` (`id`),
17
+ CONSTRAINT `FK__sourceId` FOREIGN KEY (`sourceId`) REFERENCES `elements` (`id`),
18
+ CONSTRAINT `FK__destId` FOREIGN KEY (`destId`) REFERENCES `elements` (`id`),
19
+ CONSTRAINT `FK__links` FOREIGN KEY (`linkId`) REFERENCES `links` (`id`)
20
+ )
21
+ COLLATE='utf8_general_ci'
22
+ ;
23
+
24
+ INSERT INTO history (userId,operation,`data`)
25
+ SELECT 1,0,json_object("id",id,"name",`name`,"repId",repId,"layerId",layerId,"className",className,"mdDescription",mdDescription,"fields",fields,"deleted",deleted,"createdAt",createdAt,"updatedAt",updatedAt)
26
+ FROM elements;
27
+
28
+ INSERT INTO history (userId,operation,`data`)
29
+ SELECT 1,100,json_object("id",id,"name",`name`,"repId",repId,"sourceId",sourceId,"destId",destId,"className",className,"mdDescription",mdDescription,"fields",fields,"deleted",deleted,"createdAt",createdAt,"updatedAt",updatedAt)
30
+ FROM links;
@@ -0,0 +1 @@
1
+ /* Replace with your SQL commands */
@@ -0,0 +1,26 @@
1
+ ALTER TABLE `elements`
2
+ CHANGE COLUMN `updatedAt` `updatedAt` DATETIME(3) NOT NULL DEFAULT current_timestamp(3) ON UPDATE current_timestamp(3) AFTER `createdAt`;
3
+
4
+ ALTER TABLE `links`
5
+ CHANGE COLUMN `updatedAt` `updatedAt` DATETIME(3) NOT NULL DEFAULT current_timestamp(3) ON UPDATE current_timestamp(3) AFTER `createdAt`;
6
+
7
+ ALTER TABLE `layers`
8
+ CHANGE COLUMN `updatedAt` `updatedAt` DATETIME(3) NOT NULL DEFAULT current_timestamp(3) ON UPDATE current_timestamp(3) AFTER `createdAt`;
9
+
10
+ CREATE OR REPLACE PROCEDURE `getUpdatedData`(
11
+ IN `p_repId` INT,
12
+ IN `p_since` DATETIME(3)
13
+ )
14
+ LANGUAGE SQL
15
+ NOT DETERMINISTIC
16
+ CONTAINS SQL
17
+ SQL SECURITY DEFINER
18
+ COMMENT ''
19
+ BEGIN
20
+ DECLARE lastUpdate DATETIME(3) DEFAULT NOW(3);
21
+ SELECT lastUpdate;
22
+ SELECT * FROM repositories WHERE id = p_repId;
23
+ SELECT * FROM elements WHERE repId = p_repId AND updatedAt > p_since;
24
+ SELECT * FROM links WHERE repId = p_repId AND updatedAt > p_since;
25
+ SELECT * FROM layers WHERE repId = p_repId AND updatedAt > p_since;
26
+ END
@@ -0,0 +1 @@
1
+ /* Replace with your SQL commands */
@@ -0,0 +1,2 @@
1
+ ALTER TABLE `repositories`
2
+ ADD COLUMN `config` JSON NOT NULL DEFAULT '{}' AFTER `deleted`;