acebase-server 1.16.2 → 1.18.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 (252) hide show
  1. package/README.md +180 -10
  2. package/bin/acebase-server.js +8 -0
  3. package/build-vars.js +2 -1
  4. package/dist/cjs/auth.js +88 -88
  5. package/dist/cjs/cluster.js +6 -56
  6. package/dist/cjs/index.d.ts +1 -1
  7. package/dist/cjs/index.js +24 -24
  8. package/dist/cjs/logger.js +73 -73
  9. package/dist/cjs/middleware/404.js +14 -14
  10. package/dist/cjs/middleware/admin-only.js +28 -28
  11. package/dist/cjs/middleware/cache.js +14 -14
  12. package/dist/cjs/middleware/connection.js +49 -49
  13. package/dist/cjs/middleware/context.js +20 -20
  14. package/dist/cjs/middleware/cors.js +50 -50
  15. package/dist/cjs/middleware/swagger.js +17 -17
  16. package/dist/cjs/middleware/user.js +57 -57
  17. package/dist/cjs/oauth-providers/dropbox.js +109 -109
  18. package/dist/cjs/oauth-providers/facebook.js +85 -85
  19. package/dist/cjs/oauth-providers/google.js +119 -119
  20. package/dist/cjs/oauth-providers/index.js +26 -26
  21. package/dist/cjs/oauth-providers/instagram.js +80 -80
  22. package/dist/cjs/oauth-providers/oauth-provider.js +20 -20
  23. package/dist/cjs/oauth-providers/spotify.js +113 -113
  24. package/dist/cjs/routes/auth-change-password.js +87 -87
  25. package/dist/cjs/routes/auth-delete.js +52 -52
  26. package/dist/cjs/routes/auth-forgot-password.js +77 -77
  27. package/dist/cjs/routes/auth-reset-password.js +97 -97
  28. package/dist/cjs/routes/auth-signin.js +46 -46
  29. package/dist/cjs/routes/auth-signout.js +61 -61
  30. package/dist/cjs/routes/auth-signup.js +142 -142
  31. package/dist/cjs/routes/auth-state.js +25 -25
  32. package/dist/cjs/routes/auth-update.js +131 -131
  33. package/dist/cjs/routes/auth-verify-email.js +71 -71
  34. package/dist/cjs/routes/auth.js +57 -54
  35. package/dist/cjs/routes/data-exists.js +33 -33
  36. package/dist/cjs/routes/data-export.js +48 -48
  37. package/dist/cjs/routes/data-get.js +70 -66
  38. package/dist/cjs/routes/data-import.js +54 -54
  39. package/dist/cjs/routes/data-index-create.js +42 -42
  40. package/dist/cjs/routes/data-index-delete.js +33 -33
  41. package/dist/cjs/routes/data-index-list.js +31 -31
  42. package/dist/cjs/routes/data-query.js +80 -70
  43. package/dist/cjs/routes/data-reflect.js +97 -86
  44. package/dist/cjs/routes/data-schema-get.js +36 -36
  45. package/dist/cjs/routes/data-schema-set.js +30 -30
  46. package/dist/cjs/routes/data-schema-test.js +43 -43
  47. package/dist/cjs/routes/data-schemas-list.js +32 -32
  48. package/dist/cjs/routes/data-set.js +85 -75
  49. package/dist/cjs/routes/data-sync-changes.js +81 -67
  50. package/dist/cjs/routes/data-sync-mutations.js +81 -67
  51. package/dist/cjs/routes/data-transaction.js +159 -139
  52. package/dist/cjs/routes/data-update.js +86 -75
  53. package/dist/cjs/routes/data.js +62 -62
  54. package/dist/cjs/routes/docs.js +258 -251
  55. package/dist/cjs/routes/meta-info.js +63 -63
  56. package/dist/cjs/routes/meta-logs.js +49 -49
  57. package/dist/cjs/routes/meta-ping.js +11 -11
  58. package/dist/cjs/routes/meta-stats.js +27 -27
  59. package/dist/cjs/routes/meta.js +19 -19
  60. package/dist/cjs/routes/oauth2-init.js +54 -54
  61. package/dist/cjs/routes/oauth2-refresh.js +42 -42
  62. package/dist/cjs/routes/oauth2-signin.js +265 -265
  63. package/dist/cjs/routes/webmanager.js +26 -26
  64. package/dist/cjs/rules.js +380 -167
  65. package/dist/cjs/sandbox.js +28 -0
  66. package/dist/cjs/schema/user.js +24 -24
  67. package/dist/cjs/server.js +410 -407
  68. package/dist/cjs/settings/email.js +2 -2
  69. package/dist/cjs/settings/index.js +175 -172
  70. package/dist/cjs/shared/clients.js +26 -26
  71. package/dist/cjs/shared/email.js +2 -2
  72. package/dist/cjs/shared/env.js +2 -2
  73. package/dist/cjs/shared/error.js +33 -33
  74. package/dist/cjs/shared/http.js +28 -28
  75. package/dist/cjs/shared/password.js +45 -45
  76. package/dist/cjs/shared/rootpath.js +16 -16
  77. package/dist/cjs/shared/signin.js +143 -143
  78. package/dist/cjs/shared/simple-fetch.js +76 -76
  79. package/dist/cjs/shared/tokens.js +79 -79
  80. package/dist/cjs/shared/validate.js +61 -61
  81. package/dist/cjs/start.js +119 -53
  82. package/dist/cjs/test.js +10 -10
  83. package/dist/cjs/websocket/index.js +331 -319
  84. package/dist/cjs/websocket/manager.js +15 -15
  85. package/dist/cjs/websocket/socket.io.js +76 -76
  86. package/dist/esm/auth.js +75 -75
  87. package/dist/esm/cluster.js +6 -54
  88. package/dist/esm/index.d.ts +1 -1
  89. package/dist/esm/index.js +4 -4
  90. package/dist/esm/logger.js +51 -51
  91. package/dist/esm/middleware/404.js +10 -10
  92. package/dist/esm/middleware/admin-only.js +24 -24
  93. package/dist/esm/middleware/cache.js +10 -10
  94. package/dist/esm/middleware/connection.js +45 -45
  95. package/dist/esm/middleware/context.js +16 -16
  96. package/dist/esm/middleware/cors.js +44 -44
  97. package/dist/esm/middleware/swagger.js +13 -13
  98. package/dist/esm/middleware/user.js +44 -44
  99. package/dist/esm/oauth-providers/dropbox.js +90 -90
  100. package/dist/esm/oauth-providers/facebook.js +66 -66
  101. package/dist/esm/oauth-providers/google.js +96 -96
  102. package/dist/esm/oauth-providers/index.js +18 -18
  103. package/dist/esm/oauth-providers/instagram.js +61 -61
  104. package/dist/esm/oauth-providers/oauth-provider.js +16 -16
  105. package/dist/esm/oauth-providers/spotify.js +92 -92
  106. package/dist/esm/routes/auth-change-password.js +72 -72
  107. package/dist/esm/routes/auth-delete.js +37 -37
  108. package/dist/esm/routes/auth-forgot-password.js +62 -62
  109. package/dist/esm/routes/auth-reset-password.js +81 -81
  110. package/dist/esm/routes/auth-signin.js +33 -33
  111. package/dist/esm/routes/auth-signout.js +47 -47
  112. package/dist/esm/routes/auth-signup.js +127 -127
  113. package/dist/esm/routes/auth-state.js +12 -12
  114. package/dist/esm/routes/auth-update.js +116 -116
  115. package/dist/esm/routes/auth-verify-email.js +57 -57
  116. package/dist/esm/routes/auth.js +53 -50
  117. package/dist/esm/routes/data-exists.js +20 -20
  118. package/dist/esm/routes/data-export.js +35 -35
  119. package/dist/esm/routes/data-get.js +56 -52
  120. package/dist/esm/routes/data-import.js +41 -41
  121. package/dist/esm/routes/data-index-create.js +28 -28
  122. package/dist/esm/routes/data-index-delete.js +20 -20
  123. package/dist/esm/routes/data-index-list.js +18 -18
  124. package/dist/esm/routes/data-query.js +66 -56
  125. package/dist/esm/routes/data-reflect.js +83 -72
  126. package/dist/esm/routes/data-schema-get.js +23 -23
  127. package/dist/esm/routes/data-schema-set.js +17 -17
  128. package/dist/esm/routes/data-schema-test.js +29 -29
  129. package/dist/esm/routes/data-schemas-list.js +19 -19
  130. package/dist/esm/routes/data-set.js +70 -60
  131. package/dist/esm/routes/data-sync-changes.js +67 -53
  132. package/dist/esm/routes/data-sync-mutations.js +67 -53
  133. package/dist/esm/routes/data-transaction.js +142 -123
  134. package/dist/esm/routes/data-update.js +71 -60
  135. package/dist/esm/routes/data.js +58 -58
  136. package/dist/esm/routes/docs.js +252 -245
  137. package/dist/esm/routes/meta-info.js +59 -59
  138. package/dist/esm/routes/meta-logs.js +35 -35
  139. package/dist/esm/routes/meta-ping.js +7 -7
  140. package/dist/esm/routes/meta-stats.js +14 -14
  141. package/dist/esm/routes/meta.js +15 -15
  142. package/dist/esm/routes/oauth2-init.js +41 -41
  143. package/dist/esm/routes/oauth2-refresh.js +29 -29
  144. package/dist/esm/routes/oauth2-signin.js +251 -251
  145. package/dist/esm/routes/webmanager.js +22 -22
  146. package/dist/esm/rules.js +374 -163
  147. package/dist/esm/sandbox.js +12 -0
  148. package/dist/esm/schema/user.js +19 -19
  149. package/dist/esm/server.js +395 -387
  150. package/dist/esm/settings/email.js +1 -1
  151. package/dist/esm/settings/index.js +168 -165
  152. package/dist/esm/shared/clients.js +22 -22
  153. package/dist/esm/shared/email.js +1 -1
  154. package/dist/esm/shared/env.js +1 -1
  155. package/dist/esm/shared/error.js +25 -25
  156. package/dist/esm/shared/http.js +22 -22
  157. package/dist/esm/shared/password.js +38 -38
  158. package/dist/esm/shared/rootpath.js +13 -13
  159. package/dist/esm/shared/signin.js +128 -128
  160. package/dist/esm/shared/simple-fetch.js +59 -59
  161. package/dist/esm/shared/tokens.js +72 -72
  162. package/dist/esm/shared/validate.js +41 -41
  163. package/dist/esm/start.js +116 -50
  164. package/dist/esm/test.js +8 -8
  165. package/dist/esm/websocket/index.js +313 -302
  166. package/dist/esm/websocket/manager.js +11 -11
  167. package/dist/esm/websocket/socket.io.js +71 -71
  168. package/dist/types/auth.d.ts +3 -3
  169. package/dist/types/cluster.d.ts +6 -1
  170. package/dist/types/index.d.ts +4 -4
  171. package/dist/types/logger.d.ts +35 -35
  172. package/dist/types/middleware/404.d.ts +7 -7
  173. package/dist/types/middleware/admin-only.d.ts +19 -19
  174. package/dist/types/middleware/cache.d.ts +3 -3
  175. package/dist/types/middleware/connection.d.ts +7 -7
  176. package/dist/types/middleware/context.d.ts +3 -3
  177. package/dist/types/middleware/cors.d.ts +25 -25
  178. package/dist/types/middleware/swagger.d.ts +3 -3
  179. package/dist/types/middleware/user.d.ts +2 -2
  180. package/dist/types/oauth-providers/dropbox.d.ts +52 -52
  181. package/dist/types/oauth-providers/facebook.d.ts +41 -41
  182. package/dist/types/oauth-providers/google.d.ts +43 -43
  183. package/dist/types/oauth-providers/index.d.ts +10 -10
  184. package/dist/types/oauth-providers/instagram.d.ts +50 -50
  185. package/dist/types/oauth-providers/oauth-provider.d.ts +74 -74
  186. package/dist/types/oauth-providers/spotify.d.ts +53 -53
  187. package/dist/types/routes/auth-change-password.d.ts +20 -20
  188. package/dist/types/routes/auth-delete.d.ts +16 -16
  189. package/dist/types/routes/auth-forgot-password.d.ts +16 -16
  190. package/dist/types/routes/auth-reset-password.d.ts +23 -23
  191. package/dist/types/routes/auth-signin.d.ts +24 -24
  192. package/dist/types/routes/auth-signout.d.ts +14 -14
  193. package/dist/types/routes/auth-signup.d.ts +32 -32
  194. package/dist/types/routes/auth-state.d.ts +13 -13
  195. package/dist/types/routes/auth-update.d.ts +33 -33
  196. package/dist/types/routes/auth-verify-email.d.ts +21 -21
  197. package/dist/types/routes/auth.d.ts +6 -6
  198. package/dist/types/routes/data-exists.d.ts +9 -9
  199. package/dist/types/routes/data-export.d.ts +10 -10
  200. package/dist/types/routes/data-get.d.ts +14 -14
  201. package/dist/types/routes/data-import.d.ts +13 -13
  202. package/dist/types/routes/data-index-create.d.ts +51 -51
  203. package/dist/types/routes/data-index-delete.d.ts +17 -17
  204. package/dist/types/routes/data-index-list.d.ts +21 -21
  205. package/dist/types/routes/data-query.d.ts +49 -49
  206. package/dist/types/routes/data-reflect.d.ts +29 -29
  207. package/dist/types/routes/data-schema-get.d.ts +11 -11
  208. package/dist/types/routes/data-schema-set.d.ts +20 -19
  209. package/dist/types/routes/data-schema-test.d.ts +19 -19
  210. package/dist/types/routes/data-schemas-list.d.ts +11 -11
  211. package/dist/types/routes/data-set.d.ts +27 -27
  212. package/dist/types/routes/data-sync-changes.d.ts +25 -28
  213. package/dist/types/routes/data-sync-mutations.d.ts +25 -28
  214. package/dist/types/routes/data-transaction.d.ts +34 -34
  215. package/dist/types/routes/data-update.d.ts +27 -27
  216. package/dist/types/routes/data.d.ts +3 -3
  217. package/dist/types/routes/docs.d.ts +3 -3
  218. package/dist/types/routes/meta-info.d.ts +11 -11
  219. package/dist/types/routes/meta-logs.d.ts +20 -20
  220. package/dist/types/routes/meta-ping.d.ts +7 -7
  221. package/dist/types/routes/meta-stats.d.ts +13 -13
  222. package/dist/types/routes/meta.d.ts +3 -3
  223. package/dist/types/routes/oauth2-init.d.ts +13 -13
  224. package/dist/types/routes/oauth2-refresh.d.ts +17 -17
  225. package/dist/types/routes/oauth2-signin.d.ts +15 -15
  226. package/dist/types/routes/webmanager.d.ts +3 -3
  227. package/dist/types/rules.d.ts +73 -34
  228. package/dist/types/sandbox.d.ts +3 -0
  229. package/dist/types/schema/user.d.ts +85 -85
  230. package/dist/types/server.d.ts +117 -111
  231. package/dist/types/settings/email.d.ts +14 -14
  232. package/dist/types/settings/index.d.ts +195 -187
  233. package/dist/types/shared/clients.d.ts +46 -46
  234. package/dist/types/shared/email.d.ts +34 -34
  235. package/dist/types/shared/env.d.ts +47 -44
  236. package/dist/types/shared/error.d.ts +15 -15
  237. package/dist/types/shared/http.d.ts +22 -21
  238. package/dist/types/shared/password.d.ts +19 -19
  239. package/dist/types/shared/rootpath.d.ts +2 -2
  240. package/dist/types/shared/signin.d.ts +31 -31
  241. package/dist/types/shared/simple-fetch.d.ts +21 -21
  242. package/dist/types/shared/tokens.d.ts +24 -24
  243. package/dist/types/shared/validate.d.ts +22 -22
  244. package/dist/types/start.d.ts +1 -1
  245. package/dist/types/test.d.ts +1 -1
  246. package/dist/types/websocket/index.d.ts +6 -6
  247. package/dist/types/websocket/manager.d.ts +99 -99
  248. package/dist/types/websocket/socket.io.d.ts +10 -10
  249. package/package.json +7 -4
  250. package/src/routes/data-schema-set.yaml +4 -0
  251. package/src/routes/data-set.yaml +5 -5
  252. package/src/routes/data-update.yaml +4 -4
@@ -1,72 +1,72 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addRoute = exports.VerifyEmailError = void 0;
13
- const tokens_1 = require("../shared/tokens");
14
- const error_1 = require("../shared/error");
15
- class VerifyEmailError extends Error {
16
- constructor(code, message) {
17
- super(message);
18
- this.code = code;
19
- }
20
- }
21
- exports.VerifyEmailError = VerifyEmailError;
22
- /**
23
- * Adds the verify_email route and returns the verification function that can be used to manually verify an email address
24
- * @param env environment
25
- * @returns returns the verification function
26
- */
27
- const addRoute = (env) => {
28
- const LOG_ACTION = 'auth.verify_email';
29
- const verifyEmailAddress = (clientIp, code) => __awaiter(void 0, void 0, void 0, function* () {
30
- const LOG_DETAILS = { ip: clientIp, uid: null };
31
- const verification = (() => {
32
- try {
33
- return (0, tokens_1.parseSignedPublicToken)(code, env.tokenSalt);
34
- }
35
- catch (err) {
36
- throw new VerifyEmailError('invalid_code', err.message);
37
- }
38
- })();
39
- LOG_DETAILS.uid = verification.uid;
40
- const snap = yield env.authRef.child(verification.uid).get();
41
- if (!snap.exists()) {
42
- env.log.error(LOG_ACTION, 'unknown_user', LOG_DETAILS);
43
- throw new VerifyEmailError('unknown_user', 'Unknown user');
44
- }
45
- const user = snap.val();
46
- user.uid = snap.key;
47
- // No need to do further checks, code was signed by us so we can trust the contents
48
- // Mark account as verified
49
- yield snap.ref.update({ email_verified: true });
50
- env.log.event(LOG_ACTION, LOG_DETAILS);
51
- });
52
- env.app.post(`/auth/${env.db.name}/verify_email`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
53
- const details = req.body;
54
- try {
55
- yield verifyEmailAddress(req.ip, details.code);
56
- res.send('OK');
57
- }
58
- catch (err) {
59
- if (err.code) {
60
- (0, error_1.sendBadRequestError)(res, err);
61
- }
62
- else {
63
- env.log.error(LOG_ACTION, 'unexpected', { ip: req.ip, message: err.message, verificaion_code: details.code });
64
- (0, error_1.sendUnexpectedError)(res, err);
65
- }
66
- }
67
- }));
68
- return verifyEmailAddress;
69
- };
70
- exports.addRoute = addRoute;
71
- exports.default = exports.addRoute;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addRoute = exports.VerifyEmailError = void 0;
13
+ const tokens_1 = require("../shared/tokens");
14
+ const error_1 = require("../shared/error");
15
+ class VerifyEmailError extends Error {
16
+ constructor(code, message) {
17
+ super(message);
18
+ this.code = code;
19
+ }
20
+ }
21
+ exports.VerifyEmailError = VerifyEmailError;
22
+ /**
23
+ * Adds the verify_email route and returns the verification function that can be used to manually verify an email address
24
+ * @param env environment
25
+ * @returns returns the verification function
26
+ */
27
+ const addRoute = (env) => {
28
+ const LOG_ACTION = 'auth.verify_email';
29
+ const verifyEmailAddress = (clientIp, code) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const LOG_DETAILS = { ip: clientIp, uid: null };
31
+ const verification = (() => {
32
+ try {
33
+ return (0, tokens_1.parseSignedPublicToken)(code, env.tokenSalt);
34
+ }
35
+ catch (err) {
36
+ throw new VerifyEmailError('invalid_code', err.message);
37
+ }
38
+ })();
39
+ LOG_DETAILS.uid = verification.uid;
40
+ const snap = yield env.authRef.child(verification.uid).get();
41
+ if (!snap.exists()) {
42
+ env.log.error(LOG_ACTION, 'unknown_user', LOG_DETAILS);
43
+ throw new VerifyEmailError('unknown_user', 'Unknown user');
44
+ }
45
+ const user = snap.val();
46
+ user.uid = snap.key;
47
+ // No need to do further checks, code was signed by us so we can trust the contents
48
+ // Mark account as verified
49
+ yield snap.ref.update({ email_verified: true });
50
+ env.log.event(LOG_ACTION, LOG_DETAILS);
51
+ });
52
+ env.router.post(`/auth/${env.db.name}/verify_email`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
53
+ const details = req.body;
54
+ try {
55
+ yield verifyEmailAddress(req.ip, details.code);
56
+ res.send('OK');
57
+ }
58
+ catch (err) {
59
+ if (err.code) {
60
+ (0, error_1.sendBadRequestError)(res, err);
61
+ }
62
+ else {
63
+ env.log.error(LOG_ACTION, 'unexpected', { ip: req.ip, message: err.message, verificaion_code: details.code });
64
+ (0, error_1.sendUnexpectedError)(res, err);
65
+ }
66
+ }
67
+ }));
68
+ return verifyEmailAddress;
69
+ };
70
+ exports.addRoute = addRoute;
71
+ exports.default = exports.addRoute;
72
72
  //# sourceMappingURL=auth-verify-email.js.map
@@ -1,55 +1,58 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addAuthenticionRoutes = void 0;
4
- const user_1 = require("../middleware/user");
5
- const auth_state_1 = require("./auth-state");
6
- const auth_signin_1 = require("./auth-signin");
7
- const auth_signout_1 = require("./auth-signout");
8
- const auth_verify_email_1 = require("./auth-verify-email");
9
- const auth_reset_password_1 = require("./auth-reset-password");
10
- const auth_change_password_1 = require("./auth-change-password");
11
- const auth_signup_1 = require("./auth-signup");
12
- const auth_update_1 = require("./auth-update");
13
- const auth_delete_1 = require("./auth-delete");
14
- const oauth2_init_1 = require("./oauth2-init");
15
- const oauth2_signin_1 = require("./oauth2-signin");
16
- const oauth2_refresh_1 = require("./oauth2-refresh");
17
- const addAuthenticionRoutes = (env) => {
18
- if (!env.config.auth.enabled) {
19
- throw new Error('Authentication not enabled in the server settings');
20
- }
21
- // Bearer authentication middleware
22
- (0, user_1.addMiddleware)(env);
23
- // Auth state endpoint
24
- (0, auth_state_1.addRoute)(env);
25
- // signin endpoint
26
- (0, auth_signin_1.addRoute)(env);
27
- // signout endpoint
28
- (0, auth_signout_1.addRoute)(env);
29
- // verify email endpoint
30
- const verifyEmailAddress = (0, auth_verify_email_1.addRoute)(env);
31
- // reset password endpoint
32
- const resetPassword = (0, auth_reset_password_1.addRoute)(env);
33
- // change password endpoint
34
- (0, auth_change_password_1.addRoute)(env);
35
- // signup endpoint
36
- (0, auth_signup_1.addRoute)(env);
37
- // update enpoint
38
- (0, auth_update_1.addRoute)(env);
39
- // delete endpoint
40
- (0, auth_delete_1.addRoute)(env);
41
- // OAuth2 init endpoint
42
- (0, oauth2_init_1.addRoute)(env);
43
- // OAuth2 signin endpoint
44
- (0, oauth2_signin_1.addRoute)(env);
45
- // OAuth2 token refresh endpoint
46
- (0, oauth2_refresh_1.addRoute)(env);
47
- // Return auth functions that can be used directly through an AceBaseServer instance
48
- return {
49
- verifyEmailAddress,
50
- resetPassword,
51
- };
52
- };
53
- exports.addAuthenticionRoutes = addAuthenticionRoutes;
54
- exports.default = exports.addAuthenticionRoutes;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAuthenticionRoutes = void 0;
4
+ const user_1 = require("../middleware/user");
5
+ const auth_state_1 = require("./auth-state");
6
+ const auth_signin_1 = require("./auth-signin");
7
+ const auth_signout_1 = require("./auth-signout");
8
+ const auth_verify_email_1 = require("./auth-verify-email");
9
+ const auth_forgot_password_1 = require("./auth-forgot-password");
10
+ const auth_reset_password_1 = require("./auth-reset-password");
11
+ const auth_change_password_1 = require("./auth-change-password");
12
+ const auth_signup_1 = require("./auth-signup");
13
+ const auth_update_1 = require("./auth-update");
14
+ const auth_delete_1 = require("./auth-delete");
15
+ const oauth2_init_1 = require("./oauth2-init");
16
+ const oauth2_signin_1 = require("./oauth2-signin");
17
+ const oauth2_refresh_1 = require("./oauth2-refresh");
18
+ const addAuthenticionRoutes = (env) => {
19
+ if (!env.config.auth.enabled) {
20
+ throw new Error('Authentication not enabled in the server settings');
21
+ }
22
+ // Bearer authentication middleware
23
+ (0, user_1.addMiddleware)(env);
24
+ // Auth state endpoint
25
+ (0, auth_state_1.addRoute)(env);
26
+ // signin endpoint
27
+ (0, auth_signin_1.addRoute)(env);
28
+ // signout endpoint
29
+ (0, auth_signout_1.addRoute)(env);
30
+ // verify email endpoint
31
+ const verifyEmailAddress = (0, auth_verify_email_1.addRoute)(env);
32
+ // forgot password endpoint (issue password reset)
33
+ (0, auth_forgot_password_1.addRoute)(env);
34
+ // reset password endpoint (finish password reset)
35
+ const resetPassword = (0, auth_reset_password_1.addRoute)(env);
36
+ // change password endpoint
37
+ (0, auth_change_password_1.addRoute)(env);
38
+ // signup endpoint
39
+ (0, auth_signup_1.addRoute)(env);
40
+ // update enpoint
41
+ (0, auth_update_1.addRoute)(env);
42
+ // delete endpoint
43
+ (0, auth_delete_1.addRoute)(env);
44
+ // OAuth2 init endpoint
45
+ (0, oauth2_init_1.addRoute)(env);
46
+ // OAuth2 signin endpoint
47
+ (0, oauth2_signin_1.addRoute)(env);
48
+ // OAuth2 token refresh endpoint
49
+ (0, oauth2_refresh_1.addRoute)(env);
50
+ // Return auth functions that can be used directly through an AceBaseServer instance
51
+ return {
52
+ verifyEmailAddress,
53
+ resetPassword,
54
+ };
55
+ };
56
+ exports.addAuthenticionRoutes = addAuthenticionRoutes;
57
+ exports.default = exports.addAuthenticionRoutes;
55
58
  //# sourceMappingURL=auth.js.map
@@ -1,34 +1,34 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addRoute = void 0;
13
- const error_1 = require("../shared/error");
14
- const addRoute = (env) => {
15
- env.app.get(`/exists/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
- // Exists query
17
- const path = req.path.slice(env.db.name.length + 9);
18
- const access = env.rules.userHasAccess(req.user, path, false);
19
- if (!access.allow) {
20
- return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
21
- }
22
- try {
23
- const exists = yield env.db.ref(path).exists();
24
- res.send({ exists });
25
- }
26
- catch (err) {
27
- res.statusCode = 500;
28
- res.send(err);
29
- }
30
- }));
31
- };
32
- exports.addRoute = addRoute;
33
- exports.default = exports.addRoute;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addRoute = void 0;
13
+ const error_1 = require("../shared/error");
14
+ const addRoute = (env) => {
15
+ env.router.get(`/exists/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ // Exists query
17
+ const path = req.path.slice(env.db.name.length + 9);
18
+ const access = yield env.rules.isOperationAllowed(req.user, path, 'exists', { context: req.context });
19
+ if (!access.allow) {
20
+ return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
21
+ }
22
+ try {
23
+ const exists = yield env.db.ref(path).exists();
24
+ res.send({ exists });
25
+ }
26
+ catch (err) {
27
+ res.statusCode = 500;
28
+ res.send(err);
29
+ }
30
+ }));
31
+ };
32
+ exports.addRoute = addRoute;
33
+ exports.default = exports.addRoute;
34
34
  //# sourceMappingURL=data-exists.js.map
@@ -1,49 +1,49 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addRoute = void 0;
13
- const error_1 = require("../shared/error");
14
- const addRoute = (env) => {
15
- env.app.get(`/export/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
- // Export API
17
- const path = req.path.slice(env.db.name.length + 9);
18
- const access = env.rules.userHasAccess(req.user, path, false);
19
- if (!access.allow) {
20
- return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
21
- }
22
- const format = req.query.format || 'json';
23
- const type_safe = req.query.type_safe !== '0';
24
- const write = (chunk) => __awaiter(void 0, void 0, void 0, function* () {
25
- const ok = res.write(chunk);
26
- if (!ok) {
27
- yield new Promise(resolve => res.once('drain', resolve));
28
- }
29
- });
30
- const ref = env.db.ref(path);
31
- res.setHeader('Content-Disposition', `attachment; filename=${ref.key || 'export'}.json`); // Will be treated as a download in browser
32
- try {
33
- yield ref.export(write, { format, type_safe });
34
- }
35
- catch (err) {
36
- env.debug.error(`Error exporting data for path "/${path}": `, err);
37
- if (!res.headersSent) {
38
- res.statusCode = 500;
39
- res.send(err);
40
- }
41
- }
42
- finally {
43
- res.end();
44
- }
45
- }));
46
- };
47
- exports.addRoute = addRoute;
48
- exports.default = exports.addRoute;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addRoute = void 0;
13
+ const error_1 = require("../shared/error");
14
+ const addRoute = (env) => {
15
+ env.router.get(`/export/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ // Export API
17
+ const path = req.path.slice(env.db.name.length + 9);
18
+ const access = yield env.rules.isOperationAllowed(req.user, path, 'export', { context: req.context });
19
+ if (!access.allow) {
20
+ return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
21
+ }
22
+ const format = req.query.format || 'json';
23
+ const type_safe = req.query.type_safe !== '0';
24
+ const write = (chunk) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const ok = res.write(chunk);
26
+ if (!ok) {
27
+ yield new Promise(resolve => res.once('drain', resolve));
28
+ }
29
+ });
30
+ const ref = env.db.ref(path);
31
+ res.setHeader('Content-Disposition', `attachment; filename=${ref.key || 'export'}.json`); // Will be treated as a download in browser
32
+ try {
33
+ yield ref.export(write, { format, type_safe });
34
+ }
35
+ catch (err) {
36
+ env.debug.error(`Error exporting data for path "/${path}": `, err);
37
+ if (!res.headersSent) {
38
+ res.statusCode = 500;
39
+ res.send(err);
40
+ }
41
+ }
42
+ finally {
43
+ res.end();
44
+ }
45
+ }));
46
+ };
47
+ exports.addRoute = addRoute;
48
+ exports.default = exports.addRoute;
49
49
  //# sourceMappingURL=data-export.js.map
@@ -1,67 +1,71 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addRoute = void 0;
13
- const acebase_core_1 = require("acebase-core");
14
- const error_1 = require("../shared/error");
15
- const addRoute = (env) => {
16
- env.app.get(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
- var _a;
18
- // Request data
19
- const path = req.path.slice(env.db.name.length + 7);
20
- const access = env.rules.userHasAccess(req.user, path, false);
21
- if (!access.allow) {
22
- return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
23
- }
24
- const options = {};
25
- if (req.query.include) {
26
- options.include = req.query.include.split(',');
27
- }
28
- if (req.query.exclude) {
29
- options.exclude = req.query.exclude.split(',');
30
- }
31
- if (typeof req.query.child_objects === 'boolean') {
32
- options.child_objects = req.query.child_objects;
33
- }
34
- if (path === '') {
35
- // If user has access to the root of database (NOT recommended for others than admin...)
36
- // Do not return private server data. If the admin user wants access, they should use
37
- // direct requests on those paths (GET /data/dbname/__auth__), or use reflection
38
- if (options.include) {
39
- // Remove all includes for private paths
40
- options.include = options.include.filter(path => !path.startsWith('__'));
41
- }
42
- // Add private paths to exclude
43
- options.exclude = [...options.exclude || [], '__auth__', '__log__'];
44
- }
45
- try {
46
- // const snap = await db.ref(path).get(options);
47
- // const value = snap.val(), context = snap.context();
48
- const { value, context } = yield env.db.api.get(path, options);
49
- if (!((_a = env.config.transactions) === null || _a === void 0 ? void 0 : _a.log)) {
50
- delete context.acebase_cursor;
51
- }
52
- const serialized = acebase_core_1.Transport.serialize(value);
53
- res.setHeader('AceBase-Context', JSON.stringify(context));
54
- res.send({
55
- exists: value !== null,
56
- val: serialized.val,
57
- map: serialized.map,
58
- });
59
- }
60
- catch (err) {
61
- res.status(500).send(err);
62
- }
63
- }));
64
- };
65
- exports.addRoute = addRoute;
66
- exports.default = exports.addRoute;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addRoute = void 0;
13
+ const acebase_core_1 = require("acebase-core");
14
+ const error_1 = require("../shared/error");
15
+ const addRoute = (env) => {
16
+ env.router.get(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
+ var _a;
18
+ // Request data
19
+ const path = req.path.slice(env.db.name.length + 7);
20
+ // Pre-check read access
21
+ let access = yield env.rules.isOperationAllowed(req.user, path, 'get');
22
+ if (!access.allow) {
23
+ return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
24
+ }
25
+ const options = {};
26
+ if (req.query.include) {
27
+ options.include = req.query.include.split(',');
28
+ }
29
+ if (req.query.exclude) {
30
+ options.exclude = req.query.exclude.split(',');
31
+ }
32
+ if (typeof req.query.child_objects === 'boolean') {
33
+ options.child_objects = req.query.child_objects;
34
+ }
35
+ if (path === '') {
36
+ // If user has access to the root of database (NOT recommended for others than admin...)
37
+ // Do not return private server data. If the admin user wants access, they should use
38
+ // direct requests on those paths (GET /data/dbname/__auth__), or use reflection
39
+ if (options.include) {
40
+ // Remove all includes for private paths
41
+ options.include = options.include.filter(path => !path.startsWith('__'));
42
+ }
43
+ // Add private paths to exclude
44
+ options.exclude = [...options.exclude || [], '__auth__', '__log__'];
45
+ }
46
+ // Check 'get' access
47
+ access = yield env.rules.isOperationAllowed(req.user, path, 'get', { context: req.context, options });
48
+ if (!access.allow) {
49
+ return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
50
+ }
51
+ try {
52
+ const { value, context } = yield env.db.api.get(path, options);
53
+ if (!((_a = env.config.transactions) === null || _a === void 0 ? void 0 : _a.log)) {
54
+ delete context.acebase_cursor;
55
+ }
56
+ const serialized = acebase_core_1.Transport.serialize(value);
57
+ res.setHeader('AceBase-Context', JSON.stringify(context));
58
+ res.send({
59
+ exists: value !== null,
60
+ val: serialized.val,
61
+ map: serialized.map,
62
+ });
63
+ }
64
+ catch (err) {
65
+ res.status(500).send(err);
66
+ }
67
+ }));
68
+ };
69
+ exports.addRoute = addRoute;
70
+ exports.default = exports.addRoute;
67
71
  //# sourceMappingURL=data-get.js.map