jxp 3.0.0 → 4.0.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 (219) hide show
  1. package/.env.sample +31 -6
  2. package/README.md +27 -13
  3. package/dist/bin/init_db.d.ts +3 -0
  4. package/dist/bin/init_db.d.ts.map +1 -0
  5. package/dist/bin/init_db.js +48 -0
  6. package/dist/bin/init_db.js.map +1 -0
  7. package/dist/bin/server.d.ts +4 -0
  8. package/dist/bin/server.d.ts.map +1 -0
  9. package/dist/bin/server.js +132 -0
  10. package/dist/bin/server.js.map +1 -0
  11. package/dist/bin/setup.d.ts +3 -0
  12. package/dist/bin/setup.d.ts.map +1 -0
  13. package/dist/bin/setup.js +185 -0
  14. package/dist/bin/setup.js.map +1 -0
  15. package/dist/globals.d.ts +14 -0
  16. package/dist/globals.d.ts.map +1 -0
  17. package/dist/globals.js +3 -0
  18. package/dist/globals.js.map +1 -0
  19. package/dist/libs/aggregate_guard.d.ts +5 -0
  20. package/dist/libs/aggregate_guard.d.ts.map +1 -0
  21. package/dist/libs/aggregate_guard.js +58 -0
  22. package/dist/libs/aggregate_guard.js.map +1 -0
  23. package/dist/libs/bulkwrite_guard.d.ts +5 -0
  24. package/dist/libs/bulkwrite_guard.d.ts.map +1 -0
  25. package/dist/libs/bulkwrite_guard.js +44 -0
  26. package/dist/libs/bulkwrite_guard.js.map +1 -0
  27. package/dist/libs/cache.d.ts +2 -0
  28. package/dist/libs/cache.d.ts.map +1 -0
  29. package/dist/libs/cache.js +94 -0
  30. package/dist/libs/cache.js.map +1 -0
  31. package/dist/libs/call_guard.d.ts +3 -0
  32. package/dist/libs/call_guard.d.ts.map +1 -0
  33. package/dist/libs/call_guard.js +17 -0
  34. package/dist/libs/call_guard.js.map +1 -0
  35. package/dist/libs/connection_string.d.ts +3 -0
  36. package/dist/libs/connection_string.d.ts.map +1 -0
  37. package/dist/libs/connection_string.js +4 -0
  38. package/dist/libs/connection_string.js.map +1 -0
  39. package/dist/libs/datamunging.d.ts +2 -0
  40. package/dist/libs/datamunging.d.ts.map +1 -0
  41. package/dist/libs/datamunging.js +320 -0
  42. package/dist/libs/datamunging.js.map +1 -0
  43. package/dist/libs/docs.d.ts +2 -0
  44. package/dist/libs/docs.d.ts.map +1 -0
  45. package/dist/libs/docs.js +307 -0
  46. package/dist/libs/docs.js.map +1 -0
  47. package/dist/libs/groups.d.ts +2 -0
  48. package/dist/libs/groups.d.ts.map +1 -0
  49. package/dist/libs/groups.js +136 -0
  50. package/dist/libs/groups.js.map +1 -0
  51. package/dist/libs/jxp.d.ts +4 -0
  52. package/dist/libs/jxp.d.ts.map +1 -0
  53. package/dist/libs/jxp.js +1157 -0
  54. package/dist/libs/jxp.js.map +1 -0
  55. package/dist/libs/link_index.d.ts +14 -0
  56. package/dist/libs/link_index.d.ts.map +1 -0
  57. package/dist/libs/link_index.js +37 -0
  58. package/dist/libs/link_index.js.map +1 -0
  59. package/dist/libs/load-config.d.ts +16 -0
  60. package/dist/libs/load-config.d.ts.map +1 -0
  61. package/dist/libs/load-config.js +155 -0
  62. package/dist/libs/load-config.js.map +1 -0
  63. package/dist/libs/login.d.ts +2 -0
  64. package/dist/libs/login.d.ts.map +1 -0
  65. package/dist/libs/login.js +244 -0
  66. package/dist/libs/login.js.map +1 -0
  67. package/dist/libs/modeldir.d.ts +5 -0
  68. package/dist/libs/modeldir.d.ts.map +1 -0
  69. package/dist/libs/modeldir.js +15 -0
  70. package/dist/libs/modeldir.js.map +1 -0
  71. package/dist/libs/query_limits.d.ts +2 -0
  72. package/dist/libs/query_limits.d.ts.map +1 -0
  73. package/dist/libs/query_limits.js +84 -0
  74. package/dist/libs/query_limits.js.map +1 -0
  75. package/dist/libs/query_manipulation.d.ts +3 -0
  76. package/dist/libs/query_manipulation.d.ts.map +1 -0
  77. package/{libs → dist/libs}/query_manipulation.js +22 -21
  78. package/dist/libs/query_manipulation.js.map +1 -0
  79. package/dist/libs/query_sanitize.d.ts +5 -0
  80. package/dist/libs/query_sanitize.d.ts.map +1 -0
  81. package/dist/libs/query_sanitize.js +109 -0
  82. package/dist/libs/query_sanitize.js.map +1 -0
  83. package/dist/libs/response_sanitize.d.ts +7 -0
  84. package/dist/libs/response_sanitize.d.ts.map +1 -0
  85. package/dist/libs/response_sanitize.js +57 -0
  86. package/dist/libs/response_sanitize.js.map +1 -0
  87. package/dist/libs/safe_error.d.ts +3 -0
  88. package/dist/libs/safe_error.d.ts.map +1 -0
  89. package/dist/libs/safe_error.js +14 -0
  90. package/dist/libs/safe_error.js.map +1 -0
  91. package/dist/libs/schema.d.ts +14 -0
  92. package/dist/libs/schema.d.ts.map +1 -0
  93. package/dist/libs/schema.js +98 -0
  94. package/dist/libs/schema.js.map +1 -0
  95. package/dist/libs/schema_description.d.ts +3 -0
  96. package/dist/libs/schema_description.d.ts.map +1 -0
  97. package/{libs → dist/libs}/schema_description.js +12 -21
  98. package/dist/libs/schema_description.js.map +1 -0
  99. package/dist/libs/security.d.ts +2 -0
  100. package/dist/libs/security.d.ts.map +1 -0
  101. package/dist/libs/security.js +428 -0
  102. package/dist/libs/security.js.map +1 -0
  103. package/dist/libs/setup.d.ts +2 -0
  104. package/dist/libs/setup.d.ts.map +1 -0
  105. package/dist/libs/setup.js +87 -0
  106. package/dist/libs/setup.js.map +1 -0
  107. package/dist/libs/startup-deprecations.d.ts +2 -0
  108. package/dist/libs/startup-deprecations.d.ts.map +1 -0
  109. package/dist/libs/startup-deprecations.js +21 -0
  110. package/dist/libs/startup-deprecations.js.map +1 -0
  111. package/dist/libs/startup.d.ts +16 -0
  112. package/dist/libs/startup.d.ts.map +1 -0
  113. package/dist/libs/startup.js +63 -0
  114. package/dist/libs/startup.js.map +1 -0
  115. package/dist/libs/ws.d.ts +2 -0
  116. package/dist/libs/ws.d.ts.map +1 -0
  117. package/{libs → dist/libs}/ws.js +91 -73
  118. package/dist/libs/ws.js.map +1 -0
  119. package/dist/models/apikey_model.d.ts +10 -0
  120. package/dist/models/apikey_model.d.ts.map +1 -0
  121. package/dist/models/apikey_model.js +14 -0
  122. package/dist/models/apikey_model.js.map +1 -0
  123. package/dist/models/link_model.d.ts +9 -0
  124. package/dist/models/link_model.d.ts.map +1 -0
  125. package/dist/models/link_model.js +20 -0
  126. package/dist/models/link_model.js.map +1 -0
  127. package/dist/models/refreshtoken_model.d.ts +11 -0
  128. package/dist/models/refreshtoken_model.d.ts.map +1 -0
  129. package/dist/models/refreshtoken_model.js +22 -0
  130. package/dist/models/refreshtoken_model.js.map +1 -0
  131. package/dist/models/test_model.d.ts +24 -0
  132. package/dist/models/test_model.d.ts.map +1 -0
  133. package/dist/models/test_model.js +44 -0
  134. package/dist/models/test_model.js.map +1 -0
  135. package/dist/models/token_model.d.ts +14 -0
  136. package/dist/models/token_model.d.ts.map +1 -0
  137. package/dist/models/token_model.js +25 -0
  138. package/dist/models/token_model.js.map +1 -0
  139. package/dist/models/user_model.d.ts +15 -0
  140. package/dist/models/user_model.d.ts.map +1 -0
  141. package/dist/models/user_model.js +38 -0
  142. package/dist/models/user_model.js.map +1 -0
  143. package/dist/models/usergroups_model.d.ts +9 -0
  144. package/dist/models/usergroups_model.d.ts.map +1 -0
  145. package/dist/models/usergroups_model.js +18 -0
  146. package/dist/models/usergroups_model.js.map +1 -0
  147. package/dist/types/jxp-config.d.ts +134 -0
  148. package/dist/types/jxp-config.d.ts.map +1 -0
  149. package/dist/types/jxp-config.js +3 -0
  150. package/dist/types/jxp-config.js.map +1 -0
  151. package/dist/types/schema-fields.d.ts +43 -0
  152. package/dist/types/schema-fields.d.ts.map +1 -0
  153. package/dist/types/schema-fields.js +3 -0
  154. package/dist/types/schema-fields.js.map +1 -0
  155. package/docs/aggregations.md +40 -21
  156. package/docs/api.md +55 -15
  157. package/docs/authentication.md +60 -37
  158. package/docs/bulk_writes.md +11 -8
  159. package/docs/caching.md +28 -11
  160. package/docs/changelog.md +237 -31
  161. package/docs/configuration.md +99 -118
  162. package/docs/hooks.md +12 -8
  163. package/docs/index.md +17 -17
  164. package/docs/installation.md +23 -18
  165. package/docs/permissions.md +33 -19
  166. package/docs/queries.md +9 -5
  167. package/docs/schemas.md +21 -10
  168. package/docs/special.md +4 -4
  169. package/docs/typescript.md +86 -0
  170. package/docs/websocket.md +99 -1
  171. package/mkdocs.yml +1 -0
  172. package/package.json +121 -69
  173. package/templates/api.pug +32 -0
  174. package/templates/app-server.js +43 -0
  175. package/templates/app.env.sample +8 -0
  176. package/templates/assets/api-console.js +133 -0
  177. package/templates/assets/docs.css +227 -0
  178. package/templates/index.pug +62 -2
  179. package/templates/layout.pug +17 -11
  180. package/templates/md.pug +1 -1
  181. package/templates/model.pug +117 -68
  182. package/templates/navbar.pug +14 -21
  183. package/templates/sidebar.pug +30 -0
  184. package/.env +0 -9
  185. package/.eslintrc.json +0 -20
  186. package/.jshintrc +0 -4
  187. package/.vscode/launch.json +0 -34
  188. package/.vscode/settings.json +0 -3
  189. package/Dockerfile +0 -7
  190. package/bin/init_db.js +0 -54
  191. package/bin/server.js +0 -131
  192. package/bin/setup.js +0 -190
  193. package/config_sample.json +0 -10
  194. package/docker-compose.yml +0 -32
  195. package/libs/cache.js +0 -92
  196. package/libs/connection_string.js +0 -24
  197. package/libs/datamunging.js +0 -335
  198. package/libs/docs.js +0 -162
  199. package/libs/groups.js +0 -133
  200. package/libs/jxp.js +0 -1208
  201. package/libs/login.js +0 -222
  202. package/libs/modeldir.js +0 -14
  203. package/libs/schema.js +0 -99
  204. package/libs/security.js +0 -410
  205. package/libs/setup.js +0 -90
  206. package/models/apikey_model.js +0 -10
  207. package/models/link_model.js +0 -17
  208. package/models/refreshtoken_model.js +0 -20
  209. package/models/test_model.js +0 -50
  210. package/models/token_model.js +0 -23
  211. package/models/user_model.js +0 -38
  212. package/models/usergroups_model.js +0 -15
  213. package/setup.sh +0 -3
  214. package/test/.eslintrc.json +0 -13
  215. package/test/auth.js +0 -190
  216. package/test/init.js +0 -92
  217. package/test/setup.test.js +0 -62
  218. package/test/test.js +0 -1527
  219. package/test/wstest.js.old +0 -124
package/test/auth.js DELETED
@@ -1,190 +0,0 @@
1
- process.env.NODE_ENV = 'test';
2
-
3
- var chai = require('chai');
4
- var chaiHttp = require('chai-http');
5
-
6
- var init = require("./init");
7
- var server = require("../bin/server");
8
-
9
- chai.use(chaiHttp);
10
-
11
- describe('Authentication Tests', () => {
12
- before(async function () {
13
- // First empty collections
14
- await init.empty_user_collections();
15
- console.log("Emptied collections");
16
-
17
- // Then run setup
18
- await new Promise((resolve, reject) => {
19
- chai.request(server)
20
- .post("/setup")
21
- .send({ email: init.email, password: init.password })
22
- .end((err, res) => {
23
- if (err) return reject(err);
24
- res.should.have.status(200);
25
- res.body.status.should.equal('success');
26
- console.log("Setup complete with email:", init.email);
27
- resolve();
28
- });
29
- });
30
- });
31
-
32
- var apikey = null;
33
- var token = null;
34
- var refresh_token = null;
35
- var user_id = null;
36
-
37
- describe("Login", () => {
38
- it("should login with valid credentials", (done) => {
39
- chai.request(server)
40
- .post("/login")
41
- .send({ email: init.email, password: init.password })
42
- .end((err, res) => {
43
- res.should.have.status(200);
44
- res.body.should.have.property('user_id');
45
- res.body.should.have.property('apikey');
46
- res.body.should.have.property('token');
47
- res.body.should.have.property('token_expires');
48
- res.body.should.have.property('refresh_token');
49
- res.body.should.have.property('refresh_token_expires');
50
- res.body.should.have.property('provider');
51
- apikey = res.body.apikey;
52
- token = res.body.token;
53
- user_id = res.body.user_id;
54
- refresh_token = res.body.refresh_token;
55
- done();
56
- });
57
- });
58
-
59
- it("should fail with invalid credentials", (done) => {
60
- console.log("Attempting login with invalid password for:", init.email);
61
- chai.request(server)
62
- .post("/login")
63
- .send({ email: init.email, password: "wrongpassword" })
64
- .end((err, res) => {
65
- if (err) return done(err);
66
- console.log("Response status:", res.status);
67
- console.log("Response body:", res.body);
68
- res.should.have.status(403);
69
- done();
70
- });
71
- });
72
- });
73
-
74
- describe("Token Authentication", () => {
75
- it("should authenticate with valid token", (done) => {
76
- chai.request(server)
77
- .get("/api/user")
78
- .set("Authorization", `Bearer ${token}`)
79
- .end((err, res) => {
80
- if (err) return done(err);
81
- res.should.have.status(200);
82
- res.body.data.should.be.an('array');
83
- done();
84
- });
85
- });
86
-
87
- it("should fail with invalid token", (done) => {
88
- chai.request(server)
89
- .get("/api/user")
90
- .set("Authorization", "Bearer invalidtoken")
91
- .end((err, res) => {
92
- if (err) return done(err);
93
- res.should.have.status(403);
94
- done();
95
- });
96
- });
97
- });
98
-
99
- describe("API Key Authentication", () => {
100
- it("should authenticate with valid API key in header", (done) => {
101
- chai.request(server)
102
- .get("/api/user")
103
- .set("X-API-Key", apikey)
104
- .end((err, res) => {
105
- if (err) return done(err);
106
- res.should.have.status(200);
107
- res.body.data.should.be.an('array');
108
- done();
109
- });
110
- });
111
-
112
- it("should authenticate with valid API key in query", (done) => {
113
- chai.request(server)
114
- .get(`/api/user?apikey=${apikey}`)
115
- .end((err, res) => {
116
- if (err) return done(err);
117
- res.should.have.status(200);
118
- res.body.data.should.be.an('array');
119
- done();
120
- });
121
- });
122
-
123
- it("should fail with invalid API key", (done) => {
124
- chai.request(server)
125
- .get("/api/user")
126
- .set("X-API-Key", "invalidapikey")
127
- .end((err, res) => {
128
- if (err) return done(err);
129
- res.should.have.status(403);
130
- done();
131
- });
132
- });
133
- });
134
-
135
- describe("Refresh Token", () => {
136
- it("should refresh token successfully", (done) => {
137
- chai.request(server)
138
- .post("/refresh")
139
- .set("Authorization", `Bearer ${refresh_token}`)
140
- .end((err, res) => {
141
- if (err) return done(err);
142
- res.should.have.status(200);
143
- res.body.should.have.property('token');
144
- res.body.should.have.property('token_expires');
145
- res.body.should.have.property('refresh_token');
146
- res.body.should.have.property('refresh_token_expires');
147
- res.body.token.should.not.eql(token);
148
- res.body.refresh_token.should.not.eql(refresh_token);
149
- token = res.body.token;
150
- refresh_token = res.body.refresh_token;
151
- done();
152
- });
153
- });
154
-
155
- it("should fail with invalid refresh token", (done) => {
156
- chai.request(server)
157
- .post("/refresh")
158
- .set("Authorization", "Bearer invalidrefreshtoken")
159
- .end((err, res) => {
160
- if (err) return done(err);
161
- res.should.have.status(403);
162
- done();
163
- });
164
- });
165
- });
166
-
167
- describe("Logout", () => {
168
- it("should logout successfully", (done) => {
169
- chai.request(server)
170
- .get("/login/logout")
171
- .set("Authorization", `Bearer ${token}`)
172
- .end((err, res) => {
173
- if (err) return done(err);
174
- res.should.have.status(200);
175
- done();
176
- });
177
- });
178
-
179
- it("should not be able to use token after logout", (done) => {
180
- chai.request(server)
181
- .get("/api/user")
182
- .set("Authorization", `Bearer ${token}`)
183
- .end((err, res) => {
184
- if (err) return done(err);
185
- res.should.have.status(403);
186
- done();
187
- });
188
- });
189
- });
190
- });
package/test/init.js DELETED
@@ -1,92 +0,0 @@
1
- process.env.NODE_ENV = 'test';
2
- const path = require("path");
3
-
4
- const model_dir = path.join(process.cwd(), "./models");
5
-
6
- global.JXPSchema = require("../libs/schema");
7
-
8
- const User = require(path.join(model_dir, "user_model"));
9
- const Apikey = require(path.join(model_dir, "apikey_model"));
10
- const Test = require(path.join(model_dir, "test_model"));
11
- const cache = require("../libs/cache");
12
-
13
- const security = require("../libs/security");
14
-
15
- const empty = async model => {
16
- try {
17
- await model.deleteMany({});
18
- } catch (err) {
19
- console.error(err);
20
- throw (err);
21
- }
22
- };
23
-
24
- const post = (model, data) => {
25
- return new Promise((resolve, reject) => {
26
- const item = new model(data);
27
- item.save((err, result) => {
28
- if (err)
29
- return reject(err);
30
- return resolve(result);
31
- });
32
- });
33
- };
34
-
35
- const email = "test@freespeechpub.co.za";
36
- const password = "test";
37
- const admin_email = "admin@freespeechpub.co.za";
38
- const admin_password = "SecretPassword";
39
-
40
- const init = async () => {
41
- try {
42
- await cache.clearAll();
43
- await empty_user_collections();
44
- await post(User, { name: "Admin User", email: admin_email, password: security.encPassword(admin_password), urlid: "admin-user", admin: true });
45
- await post(User, { name: "Test User", email, password: security.encPassword(password), urlid: "test-user" });
46
- return true;
47
- } catch (err) {
48
- console.error(err);
49
- throw (err);
50
- }
51
- };
52
-
53
- const empty_user_collections = async () => {
54
- try {
55
- await empty(User);
56
- await empty(Apikey);
57
- await empty(Test);
58
- } catch (err) {
59
- console.error(err);
60
- throw (err);
61
- }
62
- }
63
-
64
- // describe('Init', () => {
65
- // beforeEach(() => {
66
- // return init();
67
- // });
68
-
69
- // describe("/GET user", () => {
70
- // it("it should GET all the users", (done) => {
71
- // chai.request(server)
72
- // .get("/api/user")
73
- // .auth(email, password)
74
- // .end((err, res) => {
75
- // res.should.have.status(200);
76
- // res.body.data.should.be.a('array');
77
- // res.body.data.length.should.be.eql(2);
78
- // done();
79
- // });
80
- // });
81
- // });
82
-
83
- // });
84
-
85
- module.exports = {
86
- init,
87
- empty_user_collections,
88
- email,
89
- password,
90
- admin_email,
91
- admin_password,
92
- };
@@ -1,62 +0,0 @@
1
- process.env.NODE_ENV = 'test';
2
- const config = require("config");
3
- const path = require("path");
4
-
5
- var model_dir = config.model_dir || path.join(process.cwd(), "./models");
6
- require(path.join(model_dir, "test_model"));
7
-
8
- var chai = require('chai');
9
- var chaiHttp = require('chai-http');
10
- var should = chai.should();
11
-
12
- var init = require("./init");
13
- var server = require("../bin/server");
14
-
15
- chai.use(chaiHttp);
16
-
17
- const mock_data = {
18
- users: [
19
- { email: init.admin_email, password: init.admin_password, name: "Admin User", admin: true, urlid: "admin-user" },
20
- { email: init.email, password: init.password, name: "Jeff", admin: false, urlid: "jeff" },
21
- ],
22
- tests: [
23
- { foo: "setup_data", bar: "setup_data" }
24
- ]
25
- }
26
- describe('Setup', () => {
27
- beforeEach(async function() {
28
- await init.empty_user_collections();
29
- console.log("Emptied collections");
30
- })
31
-
32
- describe("setup", () => {
33
- it("it should setup a primary user", (done) => {
34
- chai.request(server)
35
- .post("/setup")
36
- .send({ email: init.email, password: init.password })
37
- .end((err, res) => {
38
- // console.log(res);
39
- res.should.have.status(200);
40
- res.body.status.should.equal('success');
41
- res.body.name.should.equal('admin');
42
- res.body.email.should.equal(init.email);
43
- done();
44
- });
45
- });
46
- });
47
-
48
- describe("setup_data", () => {
49
- it("it will set the database up with custom data", (done) => {
50
- chai.request(server)
51
- .post("/setup/data")
52
- .send(mock_data)
53
- .end((err, res) => {
54
- res.should.have.status(200);
55
- res.body.status.should.equal('success');
56
- res.body.results.users.insertedCount.should.equal(2);
57
- res.body.results.tests.insertedCount.should.equal(1);
58
- done();
59
- });
60
- });
61
- })
62
- });