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,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=email.js.map
@@ -1,173 +1,176 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AceBaseServerConfig = exports.AceBaseServerTransactionSettings = exports.AceBaseServerAuthenticationSettings = exports.AUTH_ACCESS_DEFAULT = exports.AceBaseServerHttpsConfig = void 0;
4
- const fs_1 = require("fs");
5
- class AceBaseServerHttpsConfig {
6
- constructor(settings) {
7
- this.enabled = true;
8
- this.enabled = typeof settings === 'object' && settings.enabled !== false;
9
- if (!this.enabled) {
10
- return;
11
- }
12
- if (settings.keyPath) {
13
- this.key = (0, fs_1.readFileSync)(settings.keyPath);
14
- this.cert = (0, fs_1.readFileSync)(settings.certPath);
15
- }
16
- else if (settings.pfxPath) {
17
- this.pfx = (0, fs_1.readFileSync)(settings.pfxPath);
18
- this.passphrase = settings.passphrase;
19
- }
20
- }
21
- }
22
- exports.AceBaseServerHttpsConfig = AceBaseServerHttpsConfig;
23
- exports.AUTH_ACCESS_DEFAULT = {
24
- DENY_ALL: 'deny',
25
- ALLOW_ALL: 'allow',
26
- ALLOW_AUTHENTICATED: 'auth',
27
- };
28
- class AceBaseServerAuthenticationSettings {
29
- constructor(settings) {
30
- /**
31
- * Whether to enable authorization. Without authorization the entire db can be read and written to by anyone (not recommended 🤷🏼‍♂️)
32
- */
33
- this.enabled = true;
34
- /**
35
- * Whether new users creation is allowed for anyone, or just the admin
36
- */
37
- this.allowUserSignup = false;
38
- /**
39
- * How many new users can sign up per hour per IP address. not implemented yet
40
- */
41
- this.newUserRateLimit = 0;
42
- /**
43
- * How many minutes before access tokens expire. 0 for no expiration. (not implemented yet)
44
- */
45
- this.tokensExpire = 0;
46
- /**
47
- * When the server runs for the first time, what defaults to use to generate the rules.json file with. Options are: 'auth' (only authenticated access to db, default), 'deny' (deny access to anyone except admin user), 'allow' (allow access to anyone)
48
- */
49
- this.defaultAccessRule = exports.AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
50
- /**
51
- * Whether to use a separate database for auth and logging. 'v2' will store data in auth.db, which is NOT TESTED YET!
52
- */
53
- this.separateDb = false;
54
- if (typeof settings !== 'object') {
55
- settings = {};
56
- }
57
- if (typeof settings.enabled === 'boolean') {
58
- this.enabled = settings.enabled;
59
- }
60
- if (typeof settings.allowUserSignup === 'boolean') {
61
- this.allowUserSignup = settings.allowUserSignup;
62
- }
63
- if (typeof settings.newUserRateLimit === 'number') {
64
- this.newUserRateLimit = settings.newUserRateLimit;
65
- }
66
- if (typeof settings.tokensExpire === 'number') {
67
- this.tokensExpire = settings.tokensExpire;
68
- }
69
- if (typeof settings.defaultAccessRule === 'string') {
70
- this.defaultAccessRule = settings.defaultAccessRule;
71
- }
72
- if (typeof settings.defaultAdminPassword === 'string') {
73
- this.defaultAdminPassword = settings.defaultAdminPassword;
74
- }
75
- if (typeof settings.seperateDb === 'boolean') {
76
- this.separateDb = settings.seperateDb;
77
- } // Handle previous _wrong_ spelling
78
- if (typeof settings.separateDb === 'boolean') {
79
- this.separateDb = settings.separateDb;
80
- }
81
- }
82
- }
83
- exports.AceBaseServerAuthenticationSettings = AceBaseServerAuthenticationSettings;
84
- /**
85
- * TODO: Use AceBaseTransactionLogSettings from acebase
86
- */
87
- class AceBaseServerTransactionSettings {
88
- constructor(settings) {
89
- /**
90
- * Whether to enable transaction logging
91
- */
92
- this.log = false;
93
- /**
94
- * Max age in days to keep transactions in the log file
95
- */
96
- this.maxAge = 30;
97
- /**
98
- * Whether database write operations should not wait until transaction has been logged
99
- */
100
- this.noWait = false;
101
- if (typeof settings !== 'object') {
102
- return;
103
- }
104
- if (typeof settings.log === 'boolean') {
105
- this.log = settings.log;
106
- }
107
- if (typeof settings.maxAge === 'number') {
108
- this.maxAge = settings.maxAge;
109
- }
110
- if (typeof settings.noWait === 'boolean') {
111
- this.noWait = settings.noWait;
112
- }
113
- }
114
- }
115
- exports.AceBaseServerTransactionSettings = AceBaseServerTransactionSettings;
116
- class AceBaseServerConfig {
117
- constructor(settings) {
118
- this.logLevel = 'log';
119
- this.host = 'localhost';
120
- this.port = 3000;
121
- this.path = '.';
122
- this.maxPayloadSize = '10mb';
123
- this.allowOrigin = '*';
124
- this.rootPath = '';
125
- this.sponsor = false;
126
- this.logColors = true;
127
- if (typeof settings !== 'object') {
128
- settings = {};
129
- }
130
- if (typeof settings.logLevel === 'string') {
131
- this.logLevel = settings.logLevel;
132
- }
133
- if (typeof settings.host === 'string') {
134
- this.host = settings.host;
135
- }
136
- if (typeof settings.port === 'number') {
137
- this.port = settings.port;
138
- }
139
- if (typeof settings.path === 'string') {
140
- this.path = settings.path;
141
- }
142
- if (typeof settings.server === 'object') {
143
- this.server = settings.server;
144
- }
145
- if (typeof settings.rootPath === 'string') {
146
- this.rootPath = settings.rootPath.replace(/^\/|\/$/g, '');
147
- }
148
- this.https = new AceBaseServerHttpsConfig(settings.https);
149
- this.auth = new AceBaseServerAuthenticationSettings(settings.authentication);
150
- if (typeof settings.maxPayloadSize === 'string') {
151
- this.maxPayloadSize = settings.maxPayloadSize;
152
- }
153
- if (typeof settings.allowOrigin === 'string') {
154
- this.allowOrigin = settings.allowOrigin;
155
- }
156
- if (typeof settings.email === 'object') {
157
- this.email = settings.email;
158
- }
159
- this.transactions = new AceBaseServerTransactionSettings(settings.transactions);
160
- this.ipc = settings.ipc;
161
- if (typeof settings.storage === 'object') {
162
- this.storage = settings.storage;
163
- }
164
- if (typeof settings.sponsor === 'boolean') {
165
- this.sponsor = settings.sponsor;
166
- }
167
- if (typeof settings.logColors === 'boolean') {
168
- this.logColors = settings.logColors;
169
- }
170
- }
171
- }
172
- exports.AceBaseServerConfig = AceBaseServerConfig;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AceBaseServerConfig = exports.AceBaseServerTransactionSettings = exports.AceBaseServerAuthenticationSettings = exports.AUTH_ACCESS_DEFAULT = exports.AceBaseServerHttpsConfig = void 0;
4
+ const fs_1 = require("fs");
5
+ class AceBaseServerHttpsConfig {
6
+ constructor(settings) {
7
+ this.enabled = true;
8
+ this.enabled = typeof settings === 'object' && settings.enabled !== false;
9
+ if (!this.enabled) {
10
+ return;
11
+ }
12
+ if (settings.keyPath) {
13
+ this.key = (0, fs_1.readFileSync)(settings.keyPath);
14
+ this.cert = (0, fs_1.readFileSync)(settings.certPath);
15
+ }
16
+ else if (settings.pfxPath) {
17
+ this.pfx = (0, fs_1.readFileSync)(settings.pfxPath);
18
+ this.passphrase = settings.passphrase;
19
+ }
20
+ }
21
+ }
22
+ exports.AceBaseServerHttpsConfig = AceBaseServerHttpsConfig;
23
+ exports.AUTH_ACCESS_DEFAULT = {
24
+ DENY_ALL: 'deny',
25
+ ALLOW_ALL: 'allow',
26
+ ALLOW_AUTHENTICATED: 'auth',
27
+ };
28
+ class AceBaseServerAuthenticationSettings {
29
+ constructor(settings) {
30
+ /**
31
+ * Whether to enable authorization. Without authorization the entire db can be read and written to by anyone (not recommended 🤷🏼‍♂️)
32
+ */
33
+ this.enabled = true;
34
+ /**
35
+ * Whether new users creation is allowed for anyone, or just the admin
36
+ */
37
+ this.allowUserSignup = false;
38
+ /**
39
+ * How many new users can sign up per hour per IP address. not implemented yet
40
+ */
41
+ this.newUserRateLimit = 0;
42
+ /**
43
+ * How many minutes before access tokens expire. 0 for no expiration. (not implemented yet)
44
+ */
45
+ this.tokensExpire = 0;
46
+ /**
47
+ * When the server runs for the first time, what defaults to use to generate the rules.json file with. Options are: 'auth' (only authenticated access to db, default), 'deny' (deny access to anyone except admin user), 'allow' (allow access to anyone)
48
+ */
49
+ this.defaultAccessRule = exports.AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
50
+ /**
51
+ * Whether to use a separate database for auth and logging. 'v2' will store data in auth.db, which is NOT TESTED YET!
52
+ */
53
+ this.separateDb = false;
54
+ if (typeof settings !== 'object') {
55
+ settings = {};
56
+ }
57
+ if (typeof settings.enabled === 'boolean') {
58
+ this.enabled = settings.enabled;
59
+ }
60
+ if (typeof settings.allowUserSignup === 'boolean') {
61
+ this.allowUserSignup = settings.allowUserSignup;
62
+ }
63
+ if (typeof settings.newUserRateLimit === 'number') {
64
+ this.newUserRateLimit = settings.newUserRateLimit;
65
+ }
66
+ if (typeof settings.tokensExpire === 'number') {
67
+ this.tokensExpire = settings.tokensExpire;
68
+ }
69
+ if (typeof settings.defaultAccessRule === 'string') {
70
+ this.defaultAccessRule = settings.defaultAccessRule;
71
+ }
72
+ if (typeof settings.defaultAdminPassword === 'string') {
73
+ this.defaultAdminPassword = settings.defaultAdminPassword;
74
+ }
75
+ if (typeof settings.seperateDb === 'boolean') {
76
+ this.separateDb = settings.seperateDb;
77
+ } // Handle previous _wrong_ spelling
78
+ if (typeof settings.separateDb === 'boolean') {
79
+ this.separateDb = settings.separateDb;
80
+ }
81
+ }
82
+ }
83
+ exports.AceBaseServerAuthenticationSettings = AceBaseServerAuthenticationSettings;
84
+ /**
85
+ * TODO: Use AceBaseTransactionLogSettings from acebase
86
+ */
87
+ class AceBaseServerTransactionSettings {
88
+ constructor(settings) {
89
+ /**
90
+ * Whether to enable transaction logging
91
+ */
92
+ this.log = false;
93
+ /**
94
+ * Max age in days to keep transactions in the log file
95
+ */
96
+ this.maxAge = 30;
97
+ /**
98
+ * Whether database write operations should not wait until transaction has been logged
99
+ */
100
+ this.noWait = false;
101
+ if (typeof settings !== 'object') {
102
+ return;
103
+ }
104
+ if (typeof settings.log === 'boolean') {
105
+ this.log = settings.log;
106
+ }
107
+ if (typeof settings.maxAge === 'number') {
108
+ this.maxAge = settings.maxAge;
109
+ }
110
+ if (typeof settings.noWait === 'boolean') {
111
+ this.noWait = settings.noWait;
112
+ }
113
+ }
114
+ }
115
+ exports.AceBaseServerTransactionSettings = AceBaseServerTransactionSettings;
116
+ class AceBaseServerConfig {
117
+ constructor(settings) {
118
+ this.logLevel = 'log';
119
+ this.host = 'localhost';
120
+ this.port = 3000;
121
+ this.path = '.';
122
+ this.maxPayloadSize = '10mb';
123
+ this.allowOrigin = '*';
124
+ this.rootPath = '';
125
+ this.sponsor = false;
126
+ this.logColors = true;
127
+ if (typeof settings !== 'object') {
128
+ settings = {};
129
+ }
130
+ if (typeof settings.logLevel === 'string') {
131
+ this.logLevel = settings.logLevel;
132
+ }
133
+ if (typeof settings.host === 'string') {
134
+ this.host = settings.host;
135
+ }
136
+ if (typeof settings.port === 'number') {
137
+ this.port = settings.port;
138
+ }
139
+ if (typeof settings.path === 'string') {
140
+ this.path = settings.path;
141
+ }
142
+ if (typeof settings.server === 'object') {
143
+ this.server = settings.server;
144
+ }
145
+ if (typeof settings.rootPath === 'string') {
146
+ this.rootPath = settings.rootPath.replace(/^\/|\/$/g, '');
147
+ }
148
+ this.https = new AceBaseServerHttpsConfig(settings.https);
149
+ this.auth = new AceBaseServerAuthenticationSettings(settings.authentication);
150
+ if (typeof settings.maxPayloadSize === 'string') {
151
+ this.maxPayloadSize = settings.maxPayloadSize;
152
+ }
153
+ if (typeof settings.allowOrigin === 'string') {
154
+ this.allowOrigin = settings.allowOrigin;
155
+ }
156
+ if (typeof settings.email === 'object') {
157
+ this.email = settings.email;
158
+ }
159
+ this.transactions = new AceBaseServerTransactionSettings(settings.transactions);
160
+ this.ipc = settings.ipc;
161
+ if (typeof settings.storage === 'object') {
162
+ this.storage = settings.storage;
163
+ }
164
+ if (typeof settings.sponsor === 'boolean') {
165
+ this.sponsor = settings.sponsor;
166
+ }
167
+ if (typeof settings.logColors === 'boolean') {
168
+ this.logColors = settings.logColors;
169
+ }
170
+ if (typeof settings.init === 'function') {
171
+ this.init = settings.init;
172
+ }
173
+ }
174
+ }
175
+ exports.AceBaseServerConfig = AceBaseServerConfig;
173
176
  //# sourceMappingURL=index.js.map
@@ -1,27 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectedClient = void 0;
4
- class ConnectedClient {
5
- /**
6
- *
7
- * @param socket Socket object used by the framework
8
- * @param id optional: use if the socket object does not have an `id` property.
9
- */
10
- constructor(socket, id) {
11
- this.socket = socket;
12
- // get id() { return this.socket.id; };
13
- this.connectedDate = new Date();
14
- /** Active event subscriptions for this client */
15
- this.subscriptions = {};
16
- /** Active realtime query subscriptions for this client */
17
- this.realtimeQueries = {};
18
- /** Currently running transactions */
19
- this.transactions = {};
20
- this.id = id !== null && id !== void 0 ? id : socket.id;
21
- if (!this.id) {
22
- throw new Error('Socket has no id');
23
- }
24
- }
25
- }
26
- exports.ConnectedClient = ConnectedClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectedClient = void 0;
4
+ class ConnectedClient {
5
+ /**
6
+ *
7
+ * @param socket Socket object used by the framework
8
+ * @param id optional: use if the socket object does not have an `id` property.
9
+ */
10
+ constructor(socket, id) {
11
+ this.socket = socket;
12
+ // get id() { return this.socket.id; };
13
+ this.connectedDate = new Date();
14
+ /** Active event subscriptions for this client */
15
+ this.subscriptions = {};
16
+ /** Active realtime query subscriptions for this client */
17
+ this.realtimeQueries = {};
18
+ /** Currently running transactions */
19
+ this.transactions = {};
20
+ this.id = id !== null && id !== void 0 ? id : socket.id;
21
+ if (!this.id) {
22
+ throw new Error('Socket has no id');
23
+ }
24
+ }
25
+ }
26
+ exports.ConnectedClient = ConnectedClient;
27
27
  //# sourceMappingURL=clients.js.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=email.js.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=env.js.map
@@ -1,34 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendUnexpectedError = exports.sendBadRequestError = exports.sendError = exports.sendUnauthorizedError = exports.sendNotAuthenticatedError = void 0;
4
- const sendNotAuthenticatedError = (res, code, message) => {
5
- res.statusCode = 401; // Unauthorized (not unauthenticated)
6
- res.statusMessage = 'Not Authenticated';
7
- res.contentType('application/json').send({ code, message });
8
- };
9
- exports.sendNotAuthenticatedError = sendNotAuthenticatedError;
10
- const sendUnauthorizedError = (res, code, message) => {
11
- res.statusCode = 403; // Forbidden
12
- res.statusMessage = 'Unauthorized';
13
- res.contentType('application/json').send({ code, message });
14
- };
15
- exports.sendUnauthorizedError = sendUnauthorizedError;
16
- const sendError = (res, err) => {
17
- res.contentType('application/json');
18
- if (typeof err.code === 'string') {
19
- (0, exports.sendBadRequestError)(res, err); //res.status(400).send({ code: err.code, message: err.message }); // Bad Request
20
- }
21
- else {
22
- (0, exports.sendUnexpectedError)(res, err); // res.status(500).send({ code: 'unknown', message: 'server error', details: err.message }); // Internal server error
23
- }
24
- };
25
- exports.sendError = sendError;
26
- const sendBadRequestError = (res, err) => {
27
- res.status(400).contentType('application/json').send({ code: err.code, message: err.message }); // Bad Request
28
- };
29
- exports.sendBadRequestError = sendBadRequestError;
30
- const sendUnexpectedError = (res, err) => {
31
- res.status(500).contentType('application/json').send({ code: 'unexpected', message: 'server error', details: err.message }); // Internal server error
32
- };
33
- exports.sendUnexpectedError = sendUnexpectedError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendUnexpectedError = exports.sendBadRequestError = exports.sendError = exports.sendUnauthorizedError = exports.sendNotAuthenticatedError = void 0;
4
+ const sendNotAuthenticatedError = (res, code, message) => {
5
+ res.statusCode = 401; // Unauthorized (not unauthenticated)
6
+ res.statusMessage = 'Not Authenticated';
7
+ res.contentType('application/json').send({ code, message });
8
+ };
9
+ exports.sendNotAuthenticatedError = sendNotAuthenticatedError;
10
+ const sendUnauthorizedError = (res, code, message) => {
11
+ res.statusCode = 403; // Forbidden
12
+ res.statusMessage = 'Unauthorized';
13
+ res.contentType('application/json').send({ code, message });
14
+ };
15
+ exports.sendUnauthorizedError = sendUnauthorizedError;
16
+ const sendError = (res, err) => {
17
+ res.contentType('application/json');
18
+ if (typeof err.code === 'string') {
19
+ (0, exports.sendBadRequestError)(res, err); //res.status(400).send({ code: err.code, message: err.message }); // Bad Request
20
+ }
21
+ else {
22
+ (0, exports.sendUnexpectedError)(res, err); // res.status(500).send({ code: 'unknown', message: 'server error', details: err.message }); // Internal server error
23
+ }
24
+ };
25
+ exports.sendError = sendError;
26
+ const sendBadRequestError = (res, err) => {
27
+ res.status(400).contentType('application/json').send({ code: err.code, message: err.message }); // Bad Request
28
+ };
29
+ exports.sendBadRequestError = sendBadRequestError;
30
+ const sendUnexpectedError = (res, err) => {
31
+ res.status(500).contentType('application/json').send({ code: 'unexpected', message: 'server error', details: err.message }); // Internal server error
32
+ };
33
+ exports.sendUnexpectedError = sendUnexpectedError;
34
34
  //# sourceMappingURL=error.js.map
@@ -1,29 +1,29 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createRouter = exports.createApp = void 0;
5
- const express = require("express");
6
- const createExpress = (_a = express.default) !== null && _a !== void 0 ? _a : express; // ESM and CJS compatible approach
7
- /**
8
- * Creates an app that handles http requests, adds json body parsing.
9
- * @param settings
10
- * @returns
11
- */
12
- const createApp = (settings) => {
13
- const app = createExpress();
14
- // When behind a trusted proxy server, req.ip and req.hostname will be set the right way
15
- app.set('trust proxy', settings.trustProxy);
16
- // Parse json request bodies
17
- app.use(express.json({ limit: settings.maxPayloadSize })); // , extended: true ?
18
- return app;
19
- };
20
- exports.createApp = createApp;
21
- /**
22
- * Creates an express router
23
- * @returns
24
- */
25
- const createRouter = () => {
26
- return createExpress.Router();
27
- };
28
- exports.createRouter = createRouter;
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createRouter = exports.createApp = void 0;
5
+ const express = require("express");
6
+ const createExpress = (_a = express.default) !== null && _a !== void 0 ? _a : express; // ESM and CJS compatible approach
7
+ /**
8
+ * Creates an app that handles http requests, adds json body parsing.
9
+ * @param settings
10
+ * @returns
11
+ */
12
+ const createApp = (settings) => {
13
+ const app = createExpress();
14
+ // When behind a trusted proxy server, req.ip and req.hostname will be set the right way
15
+ app.set('trust proxy', settings.trustProxy);
16
+ // Parse json request bodies
17
+ app.use(express.json({ limit: settings.maxPayloadSize })); // , extended: true ?
18
+ return app;
19
+ };
20
+ exports.createApp = createApp;
21
+ /**
22
+ * Creates an express router
23
+ * @returns
24
+ */
25
+ const createRouter = () => {
26
+ return createExpress.Router();
27
+ };
28
+ exports.createRouter = createRouter;
29
29
  //# sourceMappingURL=http.js.map
@@ -1,46 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOldPasswordHash = exports.getPasswordHash = exports.createPasswordHash = exports.generatePassword = void 0;
4
- const crypto = require("crypto");
5
- const generatePassword = () => {
6
- return Array.prototype.reduce.call('abcedefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ012345789!@#$%&', (password, c, i, chars) => {
7
- if (i > 15) {
8
- return password;
9
- }
10
- return password + chars[Math.floor(Math.random() * chars.length)];
11
- }, '');
12
- };
13
- exports.generatePassword = generatePassword;
14
- /**
15
- * Generates a random salt and hashes the provided password with it. The resulting salt and hash should be stored in the database
16
- * @param password password to hash
17
- */
18
- const createPasswordHash = (password) => {
19
- const length = 16;
20
- const salt = crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
21
- const hash = crypto.createHmac('sha512', salt).update(password).digest('hex');
22
- return {
23
- salt,
24
- hash,
25
- };
26
- };
27
- exports.createPasswordHash = createPasswordHash;
28
- /**
29
- * For checking passwords: uses given password and salt to get the hash that can be compared to a stored version.
30
- * @param password A password prodived by the user trying to sign in
31
- * @param salt the salt used to generate the hash, must be stored with the hash in the database
32
- */
33
- const getPasswordHash = (password, salt) => {
34
- return crypto.createHmac('sha512', salt).update(password).digest('hex');
35
- };
36
- exports.getPasswordHash = getPasswordHash;
37
- /**
38
- * Backward compatibility with old saltless md5 passwords. Becomes obsolete once all passwords have been updated (probably already so)
39
- */
40
- const getOldPasswordHash = (password) => {
41
- // Backward compatibility with old saltless md5 passwords.
42
- // Becomes obsolete once all passwords have been updated
43
- return crypto.createHash('md5').update(password).digest('hex');
44
- };
45
- exports.getOldPasswordHash = getOldPasswordHash;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOldPasswordHash = exports.getPasswordHash = exports.createPasswordHash = exports.generatePassword = void 0;
4
+ const crypto = require("crypto");
5
+ const generatePassword = () => {
6
+ return Array.prototype.reduce.call('abcedefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ012345789!@#$%&', (password, c, i, chars) => {
7
+ if (i > 15) {
8
+ return password;
9
+ }
10
+ return password + chars[Math.floor(Math.random() * chars.length)];
11
+ }, '');
12
+ };
13
+ exports.generatePassword = generatePassword;
14
+ /**
15
+ * Generates a random salt and hashes the provided password with it. The resulting salt and hash should be stored in the database
16
+ * @param password password to hash
17
+ */
18
+ const createPasswordHash = (password) => {
19
+ const length = 16;
20
+ const salt = crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
21
+ const hash = crypto.createHmac('sha512', salt).update(password).digest('hex');
22
+ return {
23
+ salt,
24
+ hash,
25
+ };
26
+ };
27
+ exports.createPasswordHash = createPasswordHash;
28
+ /**
29
+ * For checking passwords: uses given password and salt to get the hash that can be compared to a stored version.
30
+ * @param password A password prodived by the user trying to sign in
31
+ * @param salt the salt used to generate the hash, must be stored with the hash in the database
32
+ */
33
+ const getPasswordHash = (password, salt) => {
34
+ return crypto.createHmac('sha512', salt).update(password).digest('hex');
35
+ };
36
+ exports.getPasswordHash = getPasswordHash;
37
+ /**
38
+ * Backward compatibility with old saltless md5 passwords. Becomes obsolete once all passwords have been updated (probably already so)
39
+ */
40
+ const getOldPasswordHash = (password) => {
41
+ // Backward compatibility with old saltless md5 passwords.
42
+ // Becomes obsolete once all passwords have been updated
43
+ return crypto.createHash('md5').update(password).digest('hex');
44
+ };
45
+ exports.getOldPasswordHash = getOldPasswordHash;
46
46
  //# sourceMappingURL=password.js.map