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