acebase-server 1.11.0 → 1.13.1

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 (342) hide show
  1. package/.vscode/launch.json +24 -0
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/logger.js +74 -0
  4. package/dist/cjs/middleware/admin-only.js +29 -0
  5. package/dist/cjs/middleware/user.js +4 -4
  6. package/dist/cjs/routes/auth-change-password.js +7 -4
  7. package/dist/cjs/routes/auth-delete.js +9 -7
  8. package/dist/cjs/routes/auth-forgot-password.js +9 -6
  9. package/dist/cjs/routes/auth-reset-password.js +5 -3
  10. package/dist/cjs/routes/auth-signout.js +6 -4
  11. package/dist/cjs/routes/auth-signup.js +17 -15
  12. package/dist/cjs/routes/auth-update.js +9 -6
  13. package/dist/cjs/routes/auth-verify-email.js +6 -3
  14. package/dist/cjs/routes/data-index-create.js +3 -5
  15. package/dist/cjs/routes/data-index-delete.js +2 -4
  16. package/dist/cjs/routes/data-index-list.js +2 -4
  17. package/dist/cjs/routes/data-reflect.js +2 -4
  18. package/dist/cjs/routes/data-schema-get.js +2 -4
  19. package/dist/cjs/routes/data-schema-set.js +2 -4
  20. package/dist/cjs/routes/data-schema-test.js +2 -4
  21. package/dist/cjs/routes/data-schemas-list.js +2 -4
  22. package/dist/cjs/routes/data-set.js +8 -7
  23. package/dist/cjs/routes/data-transaction.js +15 -8
  24. package/dist/cjs/routes/data-update.js +8 -6
  25. package/dist/cjs/routes/meta-logs.js +50 -0
  26. package/dist/cjs/routes/meta.js +3 -0
  27. package/dist/cjs/routes/oauth2-signin.js +9 -6
  28. package/dist/cjs/server.js +3 -1
  29. package/dist/cjs/shared/rootpath.js +2 -0
  30. package/dist/cjs/shared/signin.js +8 -3
  31. package/dist/cjs/start.js +3 -0
  32. package/dist/cjs/websocket/index.js +42 -23
  33. package/dist/esm/index.d.ts +1 -0
  34. package/dist/esm/logger.js +52 -0
  35. package/dist/esm/middleware/admin-only.js +25 -0
  36. package/dist/esm/middleware/user.js +4 -4
  37. package/dist/esm/routes/auth-change-password.js +6 -3
  38. package/dist/esm/routes/auth-delete.js +7 -5
  39. package/dist/esm/routes/auth-forgot-password.js +8 -6
  40. package/dist/esm/routes/auth-reset-password.js +4 -2
  41. package/dist/esm/routes/auth-signout.js +4 -2
  42. package/dist/esm/routes/auth-signup.js +12 -10
  43. package/dist/esm/routes/auth-update.js +8 -6
  44. package/dist/esm/routes/auth-verify-email.js +6 -2
  45. package/dist/esm/routes/data-index-create.js +4 -6
  46. package/dist/esm/routes/data-index-delete.js +3 -5
  47. package/dist/esm/routes/data-index-list.js +3 -5
  48. package/dist/esm/routes/data-reflect.js +1 -4
  49. package/dist/esm/routes/data-schema-get.js +3 -5
  50. package/dist/esm/routes/data-schema-set.js +3 -5
  51. package/dist/esm/routes/data-schema-test.js +3 -5
  52. package/dist/esm/routes/data-schemas-list.js +3 -5
  53. package/dist/esm/routes/data-set.js +6 -5
  54. package/dist/esm/routes/data-transaction.js +12 -5
  55. package/dist/esm/routes/data-update.js +6 -4
  56. package/dist/esm/routes/meta-logs.js +36 -0
  57. package/dist/esm/routes/meta.js +3 -0
  58. package/dist/esm/routes/oauth2-signin.js +8 -5
  59. package/dist/esm/server.js +3 -1
  60. package/dist/esm/shared/rootpath.js +2 -0
  61. package/dist/esm/shared/signin.js +7 -3
  62. package/dist/esm/start.js +3 -0
  63. package/dist/esm/websocket/index.js +37 -22
  64. package/dist/types/logger.d.ts +35 -0
  65. package/dist/types/middleware/admin-only.d.ts +19 -0
  66. package/dist/types/routes/meta-logs.d.ts +20 -0
  67. package/dist/types/rules.d.ts +2 -2
  68. package/dist/types/shared/env.d.ts +3 -1
  69. package/dist/types/shared/signin.d.ts +1 -1
  70. package/dist/types/websocket/index.d.ts +4 -0
  71. package/package.json +5 -5
  72. package/webmanager/acebase-client-browser.min.js +16 -16
  73. package/create-package-files +0 -12
  74. package/dist/cjs/auth.js.map +0 -1
  75. package/dist/cjs/cluster.js.map +0 -1
  76. package/dist/cjs/index.js.map +0 -1
  77. package/dist/cjs/middleware/404.js.map +0 -1
  78. package/dist/cjs/middleware/cache.js.map +0 -1
  79. package/dist/cjs/middleware/connection.js.map +0 -1
  80. package/dist/cjs/middleware/context.js.map +0 -1
  81. package/dist/cjs/middleware/cors.js.map +0 -1
  82. package/dist/cjs/middleware/swagger.js.map +0 -1
  83. package/dist/cjs/middleware/user.js.map +0 -1
  84. package/dist/cjs/oauth-providers/dropbox.js.map +0 -1
  85. package/dist/cjs/oauth-providers/facebook.js.map +0 -1
  86. package/dist/cjs/oauth-providers/google.js.map +0 -1
  87. package/dist/cjs/oauth-providers/index.js.map +0 -1
  88. package/dist/cjs/oauth-providers/instagram.js.map +0 -1
  89. package/dist/cjs/oauth-providers/oauth-provider.js.map +0 -1
  90. package/dist/cjs/oauth-providers/spotify.js.map +0 -1
  91. package/dist/cjs/routes/auth-change-password.js.map +0 -1
  92. package/dist/cjs/routes/auth-delete.js.map +0 -1
  93. package/dist/cjs/routes/auth-forgot-password.js.map +0 -1
  94. package/dist/cjs/routes/auth-reset-password.js.map +0 -1
  95. package/dist/cjs/routes/auth-signin.js.map +0 -1
  96. package/dist/cjs/routes/auth-signout.js.map +0 -1
  97. package/dist/cjs/routes/auth-signup.js.map +0 -1
  98. package/dist/cjs/routes/auth-state.js.map +0 -1
  99. package/dist/cjs/routes/auth-update.js.map +0 -1
  100. package/dist/cjs/routes/auth-verify-email.js.map +0 -1
  101. package/dist/cjs/routes/auth.js.map +0 -1
  102. package/dist/cjs/routes/data-exists.js.map +0 -1
  103. package/dist/cjs/routes/data-export.js.map +0 -1
  104. package/dist/cjs/routes/data-get.js.map +0 -1
  105. package/dist/cjs/routes/data-import.js.map +0 -1
  106. package/dist/cjs/routes/data-index-create.js.map +0 -1
  107. package/dist/cjs/routes/data-index-delete.js.map +0 -1
  108. package/dist/cjs/routes/data-index-list.js.map +0 -1
  109. package/dist/cjs/routes/data-query.js.map +0 -1
  110. package/dist/cjs/routes/data-reflect.js.map +0 -1
  111. package/dist/cjs/routes/data-schema-get.js.map +0 -1
  112. package/dist/cjs/routes/data-schema-set.js.map +0 -1
  113. package/dist/cjs/routes/data-schema-test.js.map +0 -1
  114. package/dist/cjs/routes/data-schemas-list.js.map +0 -1
  115. package/dist/cjs/routes/data-set.js.map +0 -1
  116. package/dist/cjs/routes/data-sync-changes.js.map +0 -1
  117. package/dist/cjs/routes/data-sync-mutations.js.map +0 -1
  118. package/dist/cjs/routes/data-transaction.js.map +0 -1
  119. package/dist/cjs/routes/data-update.js.map +0 -1
  120. package/dist/cjs/routes/data.js.map +0 -1
  121. package/dist/cjs/routes/docs.js.map +0 -1
  122. package/dist/cjs/routes/meta-info.js.map +0 -1
  123. package/dist/cjs/routes/meta-ping.js.map +0 -1
  124. package/dist/cjs/routes/meta-stats.js.map +0 -1
  125. package/dist/cjs/routes/meta.js.map +0 -1
  126. package/dist/cjs/routes/oauth2-init.js.map +0 -1
  127. package/dist/cjs/routes/oauth2-refresh.js.map +0 -1
  128. package/dist/cjs/routes/oauth2-signin.js.map +0 -1
  129. package/dist/cjs/routes/webmanager.js.map +0 -1
  130. package/dist/cjs/rules.js.map +0 -1
  131. package/dist/cjs/schema/user.js.map +0 -1
  132. package/dist/cjs/server.js.map +0 -1
  133. package/dist/cjs/settings/email.js.map +0 -1
  134. package/dist/cjs/settings/index.js.map +0 -1
  135. package/dist/cjs/shared/clients.js.map +0 -1
  136. package/dist/cjs/shared/email.js.map +0 -1
  137. package/dist/cjs/shared/env.js.map +0 -1
  138. package/dist/cjs/shared/error.js.map +0 -1
  139. package/dist/cjs/shared/http.js.map +0 -1
  140. package/dist/cjs/shared/password.js.map +0 -1
  141. package/dist/cjs/shared/rootpath.js.map +0 -1
  142. package/dist/cjs/shared/signin.js.map +0 -1
  143. package/dist/cjs/shared/simple-fetch.js.map +0 -1
  144. package/dist/cjs/shared/tokens.js.map +0 -1
  145. package/dist/cjs/shared/validate.js.map +0 -1
  146. package/dist/cjs/start.js.map +0 -1
  147. package/dist/cjs/test.js.map +0 -1
  148. package/dist/cjs/websocket/index.js.map +0 -1
  149. package/dist/cjs/websocket/manager.js.map +0 -1
  150. package/dist/cjs/websocket/socket.io.js.map +0 -1
  151. package/dist/esm/auth.js.map +0 -1
  152. package/dist/esm/cluster.js.map +0 -1
  153. package/dist/esm/index.js.map +0 -1
  154. package/dist/esm/middleware/404.js.map +0 -1
  155. package/dist/esm/middleware/cache.js.map +0 -1
  156. package/dist/esm/middleware/connection.js.map +0 -1
  157. package/dist/esm/middleware/context.js.map +0 -1
  158. package/dist/esm/middleware/cors.js.map +0 -1
  159. package/dist/esm/middleware/swagger.js.map +0 -1
  160. package/dist/esm/middleware/user.js.map +0 -1
  161. package/dist/esm/oauth-providers/dropbox.js.map +0 -1
  162. package/dist/esm/oauth-providers/facebook.js.map +0 -1
  163. package/dist/esm/oauth-providers/google.js.map +0 -1
  164. package/dist/esm/oauth-providers/index.js.map +0 -1
  165. package/dist/esm/oauth-providers/instagram.js.map +0 -1
  166. package/dist/esm/oauth-providers/oauth-provider.js.map +0 -1
  167. package/dist/esm/oauth-providers/spotify.js.map +0 -1
  168. package/dist/esm/routes/auth-change-password.js.map +0 -1
  169. package/dist/esm/routes/auth-delete.js.map +0 -1
  170. package/dist/esm/routes/auth-forgot-password.js.map +0 -1
  171. package/dist/esm/routes/auth-reset-password.js.map +0 -1
  172. package/dist/esm/routes/auth-signin.js.map +0 -1
  173. package/dist/esm/routes/auth-signout.js.map +0 -1
  174. package/dist/esm/routes/auth-signup.js.map +0 -1
  175. package/dist/esm/routes/auth-state.js.map +0 -1
  176. package/dist/esm/routes/auth-update.js.map +0 -1
  177. package/dist/esm/routes/auth-verify-email.js.map +0 -1
  178. package/dist/esm/routes/auth.js.map +0 -1
  179. package/dist/esm/routes/data-exists.js.map +0 -1
  180. package/dist/esm/routes/data-export.js.map +0 -1
  181. package/dist/esm/routes/data-get.js.map +0 -1
  182. package/dist/esm/routes/data-import.js.map +0 -1
  183. package/dist/esm/routes/data-index-create.js.map +0 -1
  184. package/dist/esm/routes/data-index-delete.js.map +0 -1
  185. package/dist/esm/routes/data-index-list.js.map +0 -1
  186. package/dist/esm/routes/data-query.js.map +0 -1
  187. package/dist/esm/routes/data-reflect.js.map +0 -1
  188. package/dist/esm/routes/data-schema-get.js.map +0 -1
  189. package/dist/esm/routes/data-schema-set.js.map +0 -1
  190. package/dist/esm/routes/data-schema-test.js.map +0 -1
  191. package/dist/esm/routes/data-schemas-list.js.map +0 -1
  192. package/dist/esm/routes/data-set.js.map +0 -1
  193. package/dist/esm/routes/data-sync-changes.js.map +0 -1
  194. package/dist/esm/routes/data-sync-mutations.js.map +0 -1
  195. package/dist/esm/routes/data-transaction.js.map +0 -1
  196. package/dist/esm/routes/data-update.js.map +0 -1
  197. package/dist/esm/routes/data.js.map +0 -1
  198. package/dist/esm/routes/docs.js.map +0 -1
  199. package/dist/esm/routes/meta-info.js.map +0 -1
  200. package/dist/esm/routes/meta-ping.js.map +0 -1
  201. package/dist/esm/routes/meta-stats.js.map +0 -1
  202. package/dist/esm/routes/meta.js.map +0 -1
  203. package/dist/esm/routes/oauth2-init.js.map +0 -1
  204. package/dist/esm/routes/oauth2-refresh.js.map +0 -1
  205. package/dist/esm/routes/oauth2-signin.js.map +0 -1
  206. package/dist/esm/routes/webmanager.js.map +0 -1
  207. package/dist/esm/rules.js.map +0 -1
  208. package/dist/esm/schema/user.js.map +0 -1
  209. package/dist/esm/server.js.map +0 -1
  210. package/dist/esm/settings/email.js.map +0 -1
  211. package/dist/esm/settings/index.js.map +0 -1
  212. package/dist/esm/shared/clients.js.map +0 -1
  213. package/dist/esm/shared/email.js.map +0 -1
  214. package/dist/esm/shared/env.js.map +0 -1
  215. package/dist/esm/shared/error.js.map +0 -1
  216. package/dist/esm/shared/http.js.map +0 -1
  217. package/dist/esm/shared/password.js.map +0 -1
  218. package/dist/esm/shared/rootpath.js.map +0 -1
  219. package/dist/esm/shared/signin.js.map +0 -1
  220. package/dist/esm/shared/simple-fetch.js.map +0 -1
  221. package/dist/esm/shared/tokens.js.map +0 -1
  222. package/dist/esm/shared/validate.js.map +0 -1
  223. package/dist/esm/start.js.map +0 -1
  224. package/dist/esm/test.js.map +0 -1
  225. package/dist/esm/websocket/index.js.map +0 -1
  226. package/dist/esm/websocket/manager.js.map +0 -1
  227. package/dist/esm/websocket/socket.io.js.map +0 -1
  228. package/src/auth.ts +0 -87
  229. package/src/cluster.ts +0 -62
  230. package/src/index.ts +0 -4
  231. package/src/middleware/404.ts +0 -13
  232. package/src/middleware/cache.ts +0 -15
  233. package/src/middleware/connection.ts +0 -48
  234. package/src/middleware/context.ts +0 -23
  235. package/src/middleware/cors.ts +0 -49
  236. package/src/middleware/swagger.ts +0 -19
  237. package/src/middleware/user.ts +0 -51
  238. package/src/oauth-providers/dropbox.ts +0 -144
  239. package/src/oauth-providers/facebook.ts +0 -103
  240. package/src/oauth-providers/google.ts +0 -147
  241. package/src/oauth-providers/index.ts +0 -21
  242. package/src/oauth-providers/instagram.ts +0 -98
  243. package/src/oauth-providers/oauth-provider.ts +0 -65
  244. package/src/oauth-providers/spotify.ts +0 -127
  245. package/src/placeholder.d.ts +0 -12
  246. package/src/routes/auth-change-password.ts +0 -89
  247. package/src/routes/auth-change-password.yaml +0 -74
  248. package/src/routes/auth-delete.ts +0 -47
  249. package/src/routes/auth-delete.yaml +0 -78
  250. package/src/routes/auth-forgot-password.ts +0 -73
  251. package/src/routes/auth-forgot-password.yaml +0 -50
  252. package/src/routes/auth-reset-password.ts +0 -93
  253. package/src/routes/auth-reset-password.yaml +0 -54
  254. package/src/routes/auth-signin.ts +0 -55
  255. package/src/routes/auth-signin.yaml +0 -130
  256. package/src/routes/auth-signout.ts +0 -61
  257. package/src/routes/auth-signout.yaml +0 -46
  258. package/src/routes/auth-signup.ts +0 -161
  259. package/src/routes/auth-signup.yaml +0 -136
  260. package/src/routes/auth-state.ts +0 -20
  261. package/src/routes/auth-state.yaml +0 -29
  262. package/src/routes/auth-update.ts +0 -147
  263. package/src/routes/auth-update.yaml +0 -152
  264. package/src/routes/auth-verify-email.ts +0 -67
  265. package/src/routes/auth-verify-email.yaml +0 -53
  266. package/src/routes/auth.ts +0 -67
  267. package/src/routes/data-exists.ts +0 -31
  268. package/src/routes/data-exists.yaml +0 -44
  269. package/src/routes/data-export.ts +0 -51
  270. package/src/routes/data-export.yaml +0 -64
  271. package/src/routes/data-get.ts +0 -68
  272. package/src/routes/data-get.yaml +0 -54
  273. package/src/routes/data-import.ts +0 -56
  274. package/src/routes/data-import.yaml +0 -75
  275. package/src/routes/data-index-create.ts +0 -85
  276. package/src/routes/data-index-create.yaml +0 -105
  277. package/src/routes/data-index-delete.ts +0 -39
  278. package/src/routes/data-index-delete.yaml +0 -51
  279. package/src/routes/data-index-list.ts +0 -42
  280. package/src/routes/data-index-list.yaml +0 -80
  281. package/src/routes/data-query.ts +0 -97
  282. package/src/routes/data-query.yaml +0 -166
  283. package/src/routes/data-reflect.ts +0 -94
  284. package/src/routes/data-reflect.yaml +0 -124
  285. package/src/routes/data-schema-get.ts +0 -38
  286. package/src/routes/data-schema-get.yaml +0 -53
  287. package/src/routes/data-schema-set.ts +0 -38
  288. package/src/routes/data-schema-set.yaml +0 -60
  289. package/src/routes/data-schema-test.ts +0 -53
  290. package/src/routes/data-schema-test.yaml +0 -66
  291. package/src/routes/data-schemas-list.ts +0 -33
  292. package/src/routes/data-schemas-list.yaml +0 -41
  293. package/src/routes/data-set.ts +0 -80
  294. package/src/routes/data-set.yaml +0 -77
  295. package/src/routes/data-sync-changes.ts +0 -78
  296. package/src/routes/data-sync-changes.yaml +0 -67
  297. package/src/routes/data-sync-mutations.ts +0 -78
  298. package/src/routes/data-sync-mutations.yaml +0 -67
  299. package/src/routes/data-transaction-finish.yaml +0 -82
  300. package/src/routes/data-transaction-start.yaml +0 -58
  301. package/src/routes/data-transaction.ts +0 -159
  302. package/src/routes/data-update.ts +0 -81
  303. package/src/routes/data-update.yaml +0 -77
  304. package/src/routes/data.ts +0 -79
  305. package/src/routes/docs.ts +0 -249
  306. package/src/routes/meta-info.ts +0 -80
  307. package/src/routes/meta-info.yaml +0 -41
  308. package/src/routes/meta-ping.ts +0 -15
  309. package/src/routes/meta-ping.yaml +0 -23
  310. package/src/routes/meta-stats.ts +0 -31
  311. package/src/routes/meta-stats.yaml +0 -41
  312. package/src/routes/meta.ts +0 -18
  313. package/src/routes/oauth2-init.ts +0 -44
  314. package/src/routes/oauth2-init.yaml +0 -63
  315. package/src/routes/oauth2-refresh.ts +0 -39
  316. package/src/routes/oauth2-refresh.yaml +0 -65
  317. package/src/routes/oauth2-signin.ts +0 -282
  318. package/src/routes/oauth2-signin.yaml +0 -66
  319. package/src/routes/webmanager.ts +0 -29
  320. package/src/rules.ts +0 -196
  321. package/src/schema/user.ts +0 -99
  322. package/src/server.ts +0 -418
  323. package/src/settings/email.ts +0 -18
  324. package/src/settings/index.ts +0 -241
  325. package/src/shared/clients.ts +0 -31
  326. package/src/shared/email.ts +0 -33
  327. package/src/shared/env.ts +0 -38
  328. package/src/shared/error.ts +0 -37
  329. package/src/shared/http.ts +0 -26
  330. package/src/shared/password.ts +0 -41
  331. package/src/shared/rootpath.ts +0 -15
  332. package/src/shared/signin.ts +0 -143
  333. package/src/shared/simple-fetch.ts +0 -65
  334. package/src/shared/tokens.ts +0 -77
  335. package/src/shared/validate.ts +0 -53
  336. package/src/start.ts +0 -45
  337. package/src/test.ts +0 -10
  338. package/src/websocket/index.ts +0 -320
  339. package/src/websocket/manager.ts +0 -46
  340. package/src/websocket/socket.io.ts +0 -90
  341. package/tsconfig-cjs.json +0 -10
  342. package/tsconfig.json +0 -21
@@ -1,99 +0,0 @@
1
- export interface UserProfilePicture {
2
- width: number;
3
- height: number;
4
- url: string;
5
- }
6
-
7
- export interface UserSettings {
8
- [key: string]: string|number|boolean;
9
- };
10
-
11
- export type AceBaseUser = ({ username: string } | { email: string }) & {
12
- uid: string;
13
- displayName?: string;
14
- picture?: UserProfilePicture;
15
- emailVerified: boolean;
16
- /** ISO date string */
17
- created: string;
18
- /** ISO date string */
19
- prevSignin: string;
20
- prevSigninIp:string;
21
- /** ISO date string */
22
- lastSignin: string;
23
- lastSigninIp: string;
24
- changePassword: boolean;
25
- /** ISO date string */
26
- changePasswordRequested: string;
27
- /** ISO date string */
28
- changePasswordBefore: string;
29
- settings: UserSettings;
30
- };
31
-
32
- export type DbUserAccountDetails = ({ username: string } | { email: string }) & {
33
- /** uid, not stored in database object (uid is the node's key) */
34
- uid: string;
35
- username?: string;
36
- email?: string;
37
- /** if the supplied e-mail address has been verified */
38
- email_verified?: boolean;
39
- /** if the account has been disabled */
40
- is_disabled?: boolean;
41
- /** user's (public) display name */
42
- display_name?: string;
43
- /** optional profile picture */
44
- picture?: UserProfilePicture;
45
- /** password hash */
46
- password: string;
47
- /** random password salt (base64 encoded) used to generate password hash */
48
- password_salt: string;
49
- /** Code that allows a user to reset their password with */
50
- password_reset_code?: string;
51
- /** TODO: whether the user has to change their password */
52
- change_password?: boolean;
53
- /** TODO: date/time the password change was requested */
54
- change_password_requested?: Date;
55
- /** TODO: date/time the user must have changed their password */
56
- change_password_before?: Date;
57
- /** date/time the account was created */
58
- created: Date;
59
- /** creation ip address */
60
- created_ip?: string;
61
- /** date/time of last sign in */
62
- last_signin?: Date;
63
- /** ip address of last sign in */
64
- last_signin_ip?: string;
65
- /** date/time of previous sign in */
66
- prev_signin?: Date;
67
- /** ip address of previous sign in */
68
- prev_signin_ip?: string;
69
- /** date/time user last signed out */
70
- last_signout?: Date;
71
- /** ip address of last sign out */
72
- last_signout_ip?: string
73
- /** access token that allows access after signing in */
74
- access_token?: string;
75
- /** date/time access token was generateddate/time access token was generated */
76
- access_token_created?: Date;
77
- /** additional settings for this user */
78
- settings: UserSettings;
79
- };
80
-
81
- export const getPublicAccountDetails = (account: DbUserAccountDetails): AceBaseUser => {
82
- return {
83
- uid: account.uid,
84
- username: account.username,
85
- email: account.email,
86
- displayName: account.display_name,
87
- picture: account.picture,
88
- emailVerified: account.email_verified,
89
- created: account.created?.toISOString(),
90
- prevSignin: account.prev_signin?.toISOString(),
91
- prevSigninIp: account.prev_signin_ip,
92
- lastSignin: account.last_signin?.toISOString(),
93
- lastSigninIp: account.last_signin_ip,
94
- changePassword: account.change_password,
95
- changePasswordRequested: account.change_password_requested?.toISOString(),
96
- changePasswordBefore: account.change_password_before?.toISOString(),
97
- settings: account.settings
98
- };
99
- }
package/src/server.ts DELETED
@@ -1,418 +0,0 @@
1
- import { ColorStyle, DebugLogger, SimpleEventEmitter } from 'acebase-core';
2
- import { AceBaseServerSettings, AceBaseServerConfig } from './settings';
3
- import { createApp, HttpRequest, HttpResponse } from './shared/http';
4
- import { addWebsocketServer } from './websocket';
5
- import { RouteInitEnvironment } from './shared/env';
6
- import { ConnectedClient } from './shared/clients';
7
- import { AceBase, AceBaseLocalSettings, AceBaseStorageSettings } from 'acebase';
8
- import { createServer } from 'http';
9
- import { createServer as createSecureServer } from 'https';
10
- import { OAuth2Provider } from './oauth-providers/oauth-provider';
11
- import oAuth2Providers from './oauth-providers';
12
- import { PathBasedRules } from './rules';
13
- import { DbUserAccountDetails } from './schema/user';
14
- import { Api } from 'acebase-core/src/api';
15
- import addConnectionMiddleware from './middleware/connection';
16
- import addCorsMiddleware from './middleware/cors';
17
- import addAuthenticionRoutes from './routes/auth';
18
- import setupAuthentication from './auth';
19
- import addDataRoutes from './routes/data';
20
- import addDocsRoute from './routes/docs';
21
- import addWebManagerRoutes from './routes/webmanager';
22
- import addMetadataRoutes from './routes/meta';
23
- import add404Middleware from './middleware/404';
24
- import addSwaggerMiddleware from './middleware/swagger';
25
- import addCacheMiddleware from './middleware/cache';
26
-
27
- type PrivateStorageSettings = AceBaseStorageSettings & { info?: string; type?: 'data'|'transaction'|'auth'|'log' };
28
- // type PrivateLocalSettings = AceBaseLocalSettings & { storage: PrivateStorageSettings };
29
-
30
- export class AceBaseServerNotReadyError extends Error {
31
- constructor() { super('Server is not ready yet'); }
32
- }
33
-
34
- type HttpMethod = 'get'|'GET'|'put'|'PUT'|'post'|'POST'|'delete'|'DELETE';
35
-
36
- export class AceBaseServer extends SimpleEventEmitter {
37
-
38
- private _ready: boolean = false;
39
- get isReady() { return this._ready; }
40
-
41
- /**
42
- * Wait for the server to be ready to accept incoming connections
43
- * @param callback (optional) callback function that is called when ready. You can also use the returned promise
44
- * @returns returns a promise that resolves when ready
45
- */
46
- async ready(callback?: () => any) {
47
- if (!this._ready) {
48
- await this.once('ready');
49
- }
50
- callback?.();
51
- }
52
-
53
- /**
54
- * Gets the active server configuration
55
- */
56
- readonly config: AceBaseServerConfig;
57
-
58
- /**
59
- * Gets the url the server is running at
60
- */
61
- get url() {
62
- return `http${this.config.https.enabled ? 's' : ''}://${this.config.host}:${this.config.port}`;
63
- }
64
-
65
- readonly debug: DebugLogger;
66
-
67
- /**
68
- * Gets direct access to the database, this bypasses any security rules and schema validators.
69
- * You can use this to add custom event handlers ("cloud functions") to your database directly.
70
- * NOTE: your code will run in the same thread as the server, make sure you are not performing
71
- * CPU heavy tasks here. If you have to do heavy weightlifting, create a seperate app that connects
72
- * to your server with an AceBaseClient, or execute in a worker thread.
73
- * @example
74
- * server.db.ref('uploads/images').on('child_added', async snap => {
75
- * const image = snap.val();
76
- * const resizedImages = await createImageSizes(image); // Some function that creates multiple image sizes in worker thread
77
- * const targetRef = await server.db.ref('images').push(resizedImages); // Store them somewhere else
78
- * await snap.ref.remove(); // Remove original upload
79
- * });
80
- */
81
- readonly db: AceBase;
82
-
83
- /**
84
- * Exposes the used http frameworks app (currently Express) for external use.
85
- */
86
- readonly app: ReturnType<typeof createApp>;
87
-
88
- private readonly authProviders: { [provider: string]: OAuth2Provider } = {};
89
-
90
- constructor(dbname: string, options?: AceBaseServerSettings) {
91
- super();
92
-
93
- this.config = new AceBaseServerConfig(options);
94
- this.debug = new DebugLogger(this.config.logLevel, `[${dbname}]`.colorize(ColorStyle.green));
95
-
96
- if (this.config.auth.enabled && !this.config.https.enabled) {
97
- this.debug.warn(`WARNING: Authentication is enabled, but the server is not using https. Any password and other data transmitted may be intercepted!`.colorize(ColorStyle.red));
98
- }
99
- else if (!this.config.https.enabled) {
100
- this.debug.warn(`WARNING: Server is not using https, any data transmitted may be intercepted!`.colorize(ColorStyle.red));
101
- }
102
- if (!this.config.auth.enabled) {
103
- this.debug.warn(`WARNING: Authentication is disabled, *anyone* can do *anything* with your data!`.colorize(ColorStyle.red));
104
- }
105
-
106
- // Open database(s)
107
- const dbOptions: AceBaseLocalSettings & { info: string } = {
108
- logLevel: this.config.logLevel,
109
- info: 'realtime database server',
110
- // NEW: Allow storage setting like AceBaseLocalSettings - could allow using other db backend (typed, but undocumented)
111
- storage: this.config.storage || {
112
- path: this.config.path,
113
- removeVoidProperties: true,
114
- },
115
- transactions: this.config.transactions,
116
- ipc: this.config.ipc
117
- };
118
- this.db = new AceBase(dbname, dbOptions);
119
-
120
- const otherDbsPath = `${this.config.path}/${this.db.name}.acebase`;
121
- const authDb = (() => {
122
- if (!this.config.auth.enabled) {
123
- return null;
124
- }
125
- switch (this.config.auth.separateDb) {
126
- case true: return new AceBase('auth', { logLevel: dbOptions.logLevel, storage: <PrivateStorageSettings>{ path: otherDbsPath, removeVoidProperties: true, info: `${dbname} auth database` } });
127
- case 'v2': /*NOT TESTED YET*/return new AceBase(dbname, { logLevel: dbOptions.logLevel, storage: <PrivateStorageSettings>{ type: 'auth', path: this.config.path, removeVoidProperties: true, info: `${dbname} auth database` } });
128
- default: return this.db;
129
- }
130
- })();
131
-
132
- // Create Express app
133
- this.app = createApp({ trustProxy: true, maxPayloadSize: this.config.maxPayloadSize });
134
-
135
- // Initialize and start server
136
- this.init({ authDb });
137
- }
138
-
139
- private async init(env: { authDb?: AceBase }) {
140
- const config = this.config;
141
- const db = this.db;
142
- const authDb = env.authDb;
143
-
144
- // Wait for databases to be ready to use
145
- await Promise.all([
146
- db.ready(),
147
- authDb?.ready()
148
- ]);
149
-
150
- // Create http server
151
- const app = this.app;
152
- const server = config.https.enabled ? createSecureServer(config.https, app) : createServer(app);
153
- const clients = new Map<string, ConnectedClient>();
154
-
155
- const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
156
- const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
157
- const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
158
-
159
- // Setup rules
160
- const rulesFilePath = `${this.config.path}/${this.db.name}.acebase/rules.json`;
161
- const rules = new PathBasedRules(rulesFilePath, config.auth.defaultAccessRule, { db, debug: this.debug, authEnabled: this.config.auth.enabled });
162
-
163
- const routeEnv: RouteInitEnvironment = {
164
- config: this.config,
165
- server,
166
- db: db as AceBase & { api: Api },
167
- authDb,
168
- app,
169
- debug: this.debug,
170
- securityRef,
171
- authRef,
172
- logRef,
173
- tokenSalt: null,
174
- clients,
175
- authCache: null,
176
- authProviders: this.authProviders,
177
- rules
178
- };
179
-
180
- // Add connection middleware
181
- const killConnections = addConnectionMiddleware(routeEnv);
182
-
183
- // Add CORS middleware
184
- addCorsMiddleware(routeEnv);
185
-
186
- // Add cache middleware
187
- addCacheMiddleware(routeEnv);
188
-
189
- if (config.auth.enabled) {
190
- // Setup auth database
191
- await setupAuthentication(routeEnv);
192
-
193
- // Add auth endpoints
194
- const { resetPassword, verifyEmailAddress } = addAuthenticionRoutes(routeEnv);
195
- this.resetPassword = resetPassword;
196
- this.verifyEmailAddress = verifyEmailAddress;
197
- }
198
-
199
- // Add metadata endpoints
200
- addMetadataRoutes(routeEnv);
201
-
202
- // If environment is development, add API docs
203
- if (process.env.NODE_ENV?.trim?.() === 'development') {
204
- this.debug.warn('DEVELOPMENT MODE: adding API docs endpoint at /docs');
205
- addDocsRoute(routeEnv);
206
- addSwaggerMiddleware(routeEnv);
207
- }
208
-
209
- // Add data endpoints
210
- addDataRoutes(routeEnv);
211
-
212
- // Add webmanager endpoints
213
- addWebManagerRoutes(routeEnv);
214
-
215
- // Allow adding custom routes
216
- this.extend = (method: HttpMethod, ext_path: string, handler: (req: HttpRequest, res: HttpResponse) => any) => {
217
- const route = `/ext/${db.name}/${ext_path}`;
218
- this.debug.log(`Extending server: `, method, route);
219
- routeEnv.app[method.toLowerCase()](route, handler);
220
- };
221
-
222
- // Create websocket server
223
- addWebsocketServer(routeEnv);
224
-
225
- // Last but not least, add 404 handler
226
- // DISABLED because it causes server extension routes through server.extend (see above) not be be executed
227
- // add404Middleware(routeEnv);
228
-
229
- // Start listening
230
- server.listen(config.port, config.host, () => {
231
- // Ready!!
232
- this.debug.log(`"${db.name}" database server running at ${this.url}`);
233
- this._ready = true;
234
- this.emitOnce(`ready`);
235
- });
236
-
237
- // Setup pause and resume methods
238
- let paused = false;
239
- this.pause = async () => {
240
- if (paused) { throw new Error('Server is already paused'); }
241
- server.close();
242
- this.debug.warn(`Paused "${db.name}" database server at ${this.url}`);
243
- this.emit('pause');
244
- paused = true;
245
- };
246
- this.resume = async () => {
247
- if (!paused) { throw new Error('Server is not paused'); }
248
- return new Promise(resolve => {
249
- server.listen(config.port, config.host, () => {
250
- this.debug.warn(`Resumed "${db.name}" database server at ${this.url}`);
251
- this.emit('resume');
252
- paused = false;
253
- resolve();
254
- });
255
- })
256
- };
257
-
258
- // Handle SIGINT and shutdown requests
259
- const shutdown = async (request: { sigint: boolean }) => {
260
- this.debug.warn('shutting down server');
261
- routeEnv.rules.stop();
262
-
263
- const getConnectionsCount = () => {
264
- return new Promise<number>((resolve, reject) => {
265
- server.getConnections((err, connections) => {
266
- if (err) { reject(err); }
267
- else { resolve(connections); }
268
- });
269
- });
270
- };
271
- const connections = await getConnectionsCount();
272
- this.debug.log(`Server has ${connections} connections`);
273
-
274
- await new Promise<void>((resolve) => {
275
- // const interval = setInterval(async () => {
276
- // const connections = await getConnectionsCount();
277
- // this.debug.log(`Server still has ${connections} connections`);
278
- // }, 5000);
279
- // interval.unref();
280
-
281
- server.close(err => {
282
- if (err) { console.error(`server.close() error: ${err.message}`); }
283
- else { console.log(`server.close() success`); }
284
- resolve();
285
- });
286
-
287
- // If for some reason connection aren't broken in time - do proceed with shutdown sequence
288
- const timeout = setTimeout(() => {
289
- console.warn(`server.close() timed out, there are still open connections`);
290
- killConnections();
291
- // resolve();
292
- }, 5000);
293
- timeout.unref();
294
-
295
- console.log(`Closing ${clients.size} websocket connections`);
296
- clients.forEach((client, id) => {
297
- const socket = client.socket;
298
- socket.once('disconnect', reason => {
299
- console.log(`Socket ${socket.id} disconnected: ${reason}`);
300
- })
301
- socket.disconnect(true);
302
- });
303
-
304
- // clients.list.slice().forEach(client => {
305
- // client.socket.disconnect(true);
306
- // });
307
- });
308
- this.debug.warn('closing database');
309
- await db.close();
310
- this.debug.warn('shutdown complete');
311
-
312
- // Emit events to let the outside world know we shut down.
313
- // This is especially important if this instance was running in a Node.js cluster: the process will
314
- // not exit automatically after this shutdown because Node.js' IPC channel between worker and master is still open.
315
- // By sending these events, the cluster manager can determine if it should (and when to) execute process.exit()
316
-
317
- // process.emit('acebase-server-shutdown'); // Emit on process
318
- process.emit('beforeExit', request.sigint ? 130 : 0); // Emit on process
319
- try {
320
- process.send && process.send('acebase-server-shutdown'); // Send to master process when running in a Node.js cluster
321
- }
322
- catch(err) {
323
- // IPC Channel has apparently been closed already
324
- }
325
- this.emit('shutdown'); // Emit on AceBaseServer instance
326
- };
327
- this.shutdown = async () => await shutdown({ sigint: false });
328
- process.on('SIGINT', () => shutdown({ sigint: true }));
329
- }
330
-
331
- /**
332
- * Reset a user's password. This can also be done using the auth/reset_password API endpoint
333
- * @param clientIp ip address of the user
334
- * @param code reset code that was sent to the user's email address
335
- * @param newPassword new password chosen by the user
336
- */
337
- resetPassword (clientIp: string, code: string, newPassword: string): Promise<DbUserAccountDetails> {
338
- throw new AceBaseServerNotReadyError();
339
- }
340
-
341
- /**
342
- * Marks a user account's email address as validated. This can also be done using the auth/verify_email API endpoint
343
- * @param clientIp ip address of the user
344
- * @param code verification code sent to the user's email address
345
- */
346
- verifyEmailAddress (clientIp: string, code: string): Promise<void> {
347
- throw new AceBaseServerNotReadyError();
348
- }
349
-
350
- /**
351
- * Shuts down the server. Stops listening for incoming connections, breaks current connections and closes the database.
352
- * Is automatically executed when a "SIGINT" process event is received.
353
- *
354
- * Once the shutdown procedure is completed, it emits a "shutdown" event on the server instance, "acebase-server-shutdown" event on the `process`, and sends an 'acebase-server-shutdown' IPC message if Node.js clustering is used.
355
- * These events can be handled by cluster managing code to `kill` or `exit` the process safely.
356
- */
357
- shutdown() {
358
- throw new AceBaseServerNotReadyError();
359
- }
360
-
361
- /**
362
- * Temporarily stops the server from handling incoming connections, but keeps existing connections open
363
- */
364
- pause(): Promise<void> {
365
- throw new AceBaseServerNotReadyError();
366
- }
367
-
368
- /**
369
- * Resumes handling incoming connections
370
- */
371
- resume(): Promise<void> {
372
- throw new AceBaseServerNotReadyError();
373
- }
374
-
375
- /**
376
- * Extend the server API with your own custom functions. Your handler will be listening
377
- * on path /ext/[db name]/[ext_path].
378
- * @example
379
- * // Server side:
380
- * const _quotes = [...];
381
- * server.extend('get', 'quotes/random', (req, res) => {
382
- * let index = Math.round(Math.random() * _quotes.length);
383
- * res.send(quotes[index]);
384
- * })
385
- * // Client side:
386
- * client.callExtension('get', 'quotes/random')
387
- * .then(quote => {
388
- * console.log(`Got random quote: ${quote}`);
389
- * })
390
- * @param method http method to bind to
391
- * @param ext_path path to bind to (appended to /ext/)
392
- * @param handler your Express request handler callback
393
- */
394
- extend(method: HttpMethod, ext_path: string, handler: (req: HttpRequest, res: HttpResponse) => void) {
395
- throw new AceBaseServerNotReadyError();
396
- }
397
-
398
- /**
399
- * Configure an auth provider to allow users to sign in with Facebook, Google, etc
400
- * @param providerName name of the third party OAuth provider. Eg: "Facebook", "Google", "spotify" etc
401
- * @param settings API key & secret for the OAuth provider
402
- * @returns Returns the created auth provider instance, which can be used to call non-user specific methods the provider might support. (example: the Spotify auth provider supports getClientAuthToken, which allows API calls to be made to the core (non-user) spotify service)
403
- */
404
- configAuthProvider(providerName: string, settings: any) {
405
- if (!this.config.auth.enabled) {
406
- throw new Error(`Authentication is not enabled`);
407
- }
408
- try {
409
- const AuthProvider = oAuth2Providers[providerName];
410
- const provider = new AuthProvider(settings);
411
- this.authProviders[providerName] = provider;
412
- return provider;
413
- }
414
- catch(err) {
415
- throw new Error(`Failed to configure provider ${providerName}: ${err.message}`)
416
- }
417
- }
418
- }
@@ -1,18 +0,0 @@
1
- import { AceBaseEmailRequest } from '../shared/email';
2
-
3
- export interface AceBaseServerEmailServerSettings {
4
- host: string;
5
- port: number;
6
- username?: string;
7
- password?: string;
8
- secure: boolean;
9
- };
10
-
11
- export interface AceBaseServerEmailSettings {
12
-
13
- /** NOT IMPLEMENTED YET - Use send property for your own implementation */
14
- server?: AceBaseServerEmailServerSettings;
15
-
16
- /** function to call when an e-mail needs to be sent */
17
- send: (request: AceBaseEmailRequest) => Promise<void>;
18
- };