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
@@ -29,6 +29,7 @@ const webmanager_1 = require("./routes/webmanager");
29
29
  const meta_1 = require("./routes/meta");
30
30
  const swagger_1 = require("./middleware/swagger");
31
31
  const cache_1 = require("./middleware/cache");
32
+ const logger_1 = require("./logger");
32
33
  // type PrivateLocalSettings = AceBaseLocalSettings & { storage: PrivateStorageSettings };
33
34
  class AceBaseServerNotReadyError extends Error {
34
35
  constructor() { super('Server is not ready yet'); }
@@ -117,6 +118,7 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
117
118
  const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
118
119
  const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
119
120
  const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
121
+ const logger = new logger_1.DatabaseLog(logRef);
120
122
  // Setup rules
121
123
  const rulesFilePath = `${this.config.path}/${this.db.name}.acebase/rules.json`;
122
124
  const rules = new rules_1.PathBasedRules(rulesFilePath, config.auth.defaultAccessRule, { db, debug: this.debug, authEnabled: this.config.auth.enabled });
@@ -129,7 +131,7 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
129
131
  debug: this.debug,
130
132
  securityRef,
131
133
  authRef,
132
- logRef,
134
+ log: logger,
133
135
  tokenSalt: null,
134
136
  clients,
135
137
  authCache: null,
@@ -331,9 +333,9 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
331
333
  * .then(quote => {
332
334
  * console.log(`Got random quote: ${quote}`);
333
335
  * })
334
- * @param {'get'|'put'|'post'|'delete'} method
335
- * @param {string} ext_path
336
- * @param {(req: Express.Request, res: Express.Response)} handler
336
+ * @param method http method to bind to
337
+ * @param ext_path path to bind to (appended to /ext/)
338
+ * @param handler your Express request handler callback
337
339
  */
338
340
  extend(method, ext_path, handler) {
339
341
  throw new AceBaseServerNotReadyError();
@@ -20,12 +20,11 @@ class AceBaseServerHttpsConfig {
20
20
  }
21
21
  }
22
22
  exports.AceBaseServerHttpsConfig = AceBaseServerHttpsConfig;
23
- var AUTH_ACCESS_DEFAULT;
24
- (function (AUTH_ACCESS_DEFAULT) {
25
- AUTH_ACCESS_DEFAULT["DENY_ALL"] = "deny";
26
- AUTH_ACCESS_DEFAULT["ALLOW_ALL"] = "allow";
27
- AUTH_ACCESS_DEFAULT["ALLOW_AUTHENTICATED"] = "auth";
28
- })(AUTH_ACCESS_DEFAULT = exports.AUTH_ACCESS_DEFAULT || (exports.AUTH_ACCESS_DEFAULT = {}));
23
+ exports.AUTH_ACCESS_DEFAULT = {
24
+ DENY_ALL: 'deny',
25
+ ALLOW_ALL: 'allow',
26
+ ALLOW_AUTHENTICATED: 'auth'
27
+ };
29
28
  class AceBaseServerAuthenticationSettings {
30
29
  constructor(settings) {
31
30
  /**
@@ -47,7 +46,7 @@ class AceBaseServerAuthenticationSettings {
47
46
  /**
48
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)
49
48
  */
50
- this.defaultAccessRule = AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
49
+ this.defaultAccessRule = exports.AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
51
50
  /**
52
51
  * Whether to use a separate database for auth and logging. 'v2' will store data in auth.db, which is NOT TESTED YET!
53
52
  */
@@ -10,6 +10,8 @@ if (process.platform === 'win32' && currentDir.startsWith('/')) {
10
10
  // tsc-esm-fix does not handle win32 file urls correctly, the drive letter in import.meta.url is prefixed with a slash: file:///C:/dir/file.js
11
11
  currentDir = currentDir.slice(1);
12
12
  }
13
+ // tsc-esm-fix also does not use decodeURI to remove encoded characters (such as %20 for spaces)
14
+ currentDir = decodeURI(currentDir);
13
15
  exports.packageRootPath = (0, path_1.resolve)(currentDir, '../../..');
14
16
  exports.default = exports.packageRootPath;
15
17
  //# sourceMappingURL=rootpath.js.map
@@ -30,6 +30,9 @@ exports.SignInError = SignInError;
30
30
  * @returns
31
31
  */
32
32
  const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, function* () {
33
+ var _a;
34
+ const LOG_ACTION = 'auth.signin';
35
+ const LOG_DETAILS = { ip: req.ip, method: credentials.method };
33
36
  try {
34
37
  const query = env.authRef.query();
35
38
  let tokenDetails;
@@ -47,7 +50,7 @@ const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, func
47
50
  }
48
51
  break;
49
52
  }
50
- case 'private_token': {
53
+ case 'internal': {
51
54
  // Method used internally: uses the access token extracted from a public access token (see tokenDetails.access_token in above 'token' case)
52
55
  if (typeof credentials.access_token !== 'string') {
53
56
  throw new SignInError('invalid_details', 'sign in request has invalid arguments');
@@ -122,7 +125,9 @@ const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, func
122
125
  // Update db
123
126
  yield snap.ref.update(updates);
124
127
  // Log history item
125
- env.logRef.push({ action: `signin`, type: credentials.method, [credentials.method]: credentials[credentials.method], ip: req.ip, date: new Date(), success: true });
128
+ if (credentials.method !== 'internal') {
129
+ env.log.event(LOG_ACTION, LOG_DETAILS);
130
+ }
126
131
  // Add to cache
127
132
  env.authCache.set(user.uid, user);
128
133
  // Bind user to current request
@@ -131,7 +136,7 @@ const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, func
131
136
  }
132
137
  catch (err) {
133
138
  // Log error
134
- env.logRef.push(Object.assign({ action: 'signin', type: credentials.method, [credentials.method]: credentials[credentials.method], success: false, code: err.code || 'unexpected', message: err.code ? null : err.message, ip: req.ip, date: new Date() }, err.details));
139
+ env.log.error(LOG_ACTION, (_a = err.code) !== null && _a !== void 0 ? _a : 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
135
140
  throw err;
136
141
  }
137
142
  });
package/dist/cjs/start.js CHANGED
@@ -42,6 +42,9 @@ if (+getVariable('TXLOG', 0) === 1) {
42
42
  maxAge: +getVariable('TXDAYS', 30)
43
43
  };
44
44
  }
45
+ if (+getVariable('AUTH', 1) === 0) {
46
+ options.authentication = { enabled: false };
47
+ }
45
48
  const server = new server_1.AceBaseServer(dbname, options);
46
49
  server.once("ready", () => {
47
50
  var _a;
@@ -9,11 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addWebsocketServer = void 0;
12
+ exports.addWebsocketServer = exports.SocketRequestError = void 0;
13
13
  const acebase_core_1 = require("acebase-core");
14
14
  const clients_1 = require("../shared/clients");
15
15
  const tokens_1 = require("../shared/tokens");
16
16
  const socket_io_1 = require("./socket.io");
17
+ class SocketRequestError extends Error {
18
+ constructor(code, message) {
19
+ super(message);
20
+ this.code = code;
21
+ }
22
+ }
23
+ exports.SocketRequestError = SocketRequestError;
17
24
  const addWebsocketServer = (env) => {
18
25
  // TODO: Allow using uWebSockets.js server instead of Socket.IO
19
26
  const serverManager = (0, socket_io_1.createServer)(env);
@@ -106,7 +113,7 @@ const addWebsocketServer = (env) => {
106
113
  serverManager.send(event.socket, 'oauth2-signin', { error: err.message });
107
114
  }
108
115
  }));
109
- const acknowlegdeRequest = (socket, requestId) => {
116
+ const acknowledgeRequest = (socket, requestId) => {
110
117
  // Send acknowledgement
111
118
  serverManager.send(socket, 'result', {
112
119
  success: true,
@@ -122,6 +129,7 @@ const addWebsocketServer = (env) => {
122
129
  });
123
130
  };
124
131
  serverManager.on('subscribe', event => {
132
+ var _a, _b;
125
133
  // Client wants to subscribe to events on a node
126
134
  const client = getClientBySocketId(event.socket_id, 'subscribe');
127
135
  if (!client) {
@@ -131,12 +139,12 @@ const addWebsocketServer = (env) => {
131
139
  const subscriptionPath = event.data.path;
132
140
  const isSubscribed = () => subscriptionPath in client.subscriptions && client.subscriptions[subscriptionPath].some(s => s.event === event.data.event);
133
141
  if (isSubscribed()) {
134
- return acknowlegdeRequest(event.socket, event.data.req_id);
142
+ return acknowledgeRequest(event.socket, event.data.req_id);
135
143
  }
136
144
  // Get client
137
145
  // const client = clients.get(socket.id);
138
146
  if (!env.rules.userHasAccess(client.user, subscriptionPath, false)) {
139
- env.logRef.push({ action: 'subscribe', success: false, code: 'access_denied', uid: client.user ? client.user.uid : '-', path: subscriptionPath });
147
+ env.log.error('event.subscribe', 'access_denied', { uid: (_b = (_a = client.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : 'anonymous', path: subscriptionPath });
140
148
  return failRequest(event.socket, event.data.req_id, 'access_denied');
141
149
  }
142
150
  const callback = (err, path, currentValue, previousValue, context) => {
@@ -177,7 +185,7 @@ const addWebsocketServer = (env) => {
177
185
  let subscr = { path: subscriptionPath, event: event.data.event, callback };
178
186
  pathSubs.push(subscr);
179
187
  env.db.api.subscribe(subscriptionPath, event.data.event, callback);
180
- acknowlegdeRequest(event.socket, event.data.req_id);
188
+ acknowledgeRequest(event.socket, event.data.req_id);
181
189
  });
182
190
  serverManager.on('unsubscribe', event => {
183
191
  // Client unsubscribes from events on a node
@@ -190,7 +198,7 @@ const addWebsocketServer = (env) => {
190
198
  let pathSubs = client.subscriptions[event.data.path];
191
199
  if (!pathSubs) {
192
200
  // We have no knowledge of any active subscriptions on this path
193
- return acknowlegdeRequest(event.socket, event.data.req_id);
201
+ return acknowledgeRequest(event.socket, event.data.req_id);
194
202
  }
195
203
  let remove = pathSubs;
196
204
  if (event.data.event) {
@@ -207,7 +215,7 @@ const addWebsocketServer = (env) => {
207
215
  // No subscriptions left on this path, remove the path entry
208
216
  delete client.subscriptions[event.data.path];
209
217
  }
210
- return acknowlegdeRequest(event.socket, event.data.req_id);
218
+ return acknowledgeRequest(event.socket, event.data.req_id);
211
219
  });
212
220
  serverManager.on('query-unsubscribe', event => {
213
221
  // Client unsubscribing from realtime query events
@@ -218,15 +226,18 @@ const addWebsocketServer = (env) => {
218
226
  env.debug.verbose(`Client ${event.socket_id} is unsubscribing from realtime query "${event.data.query_id}"`);
219
227
  // const client = clients.get(socket.id);
220
228
  delete client.realtimeQueries[event.data.query_id];
221
- acknowlegdeRequest(event.socket, event.data.req_id);
229
+ acknowledgeRequest(event.socket, event.data.req_id);
222
230
  });
223
231
  const TRANSACTION_TIMEOUT_MS = 10000; // 10s to finish a started transaction
224
232
  serverManager.on('transaction-start', event => {
233
+ var _a, _b, _c;
225
234
  // Start transaction
226
235
  const client = getClientBySocketId(event.socket_id, 'transaction-start');
227
- if (!client) {
236
+ if (!client || !event.data) {
228
237
  return;
229
238
  }
239
+ const LOG_ACTION = 'socket.transaction.start';
240
+ const LOG_DETAILS = { ip: event.socket.conn.remoteAddress, uid: (_b = (_a = client.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path: event.data.path };
230
241
  env.debug.verbose(`Client ${event.socket_id} is sending transaction start request on path "${event.data.path}"`);
231
242
  const data = event.data;
232
243
  const tx = {
@@ -238,11 +249,14 @@ const addWebsocketServer = (env) => {
238
249
  timeout: setTimeout(() => {
239
250
  delete client.transactions[tx.id];
240
251
  tx.finish(); // Finish without value cancels the transaction
252
+ env.log.error(LOG_ACTION, 'timeout', LOG_DETAILS);
241
253
  serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: 'timeout' });
242
254
  }, TRANSACTION_TIMEOUT_MS)
243
255
  };
244
- if (!env.rules.userHasAccess(client.user, data.path, true)) {
256
+ const access = env.rules.userHasAccess(client.user, data.path, true);
257
+ if (!access.allow) {
245
258
  // throw new AccessDeniedError(`access_denied`);
259
+ env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_c = access.rulePath) !== null && _c !== void 0 ? _c : null }), access.details);
246
260
  return serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: 'access_denied' });
247
261
  }
248
262
  // Bind to client
@@ -264,34 +278,39 @@ const addWebsocketServer = (env) => {
264
278
  }, { context: tx.context });
265
279
  });
266
280
  serverManager.on('transaction-finish', (event) => __awaiter(void 0, void 0, void 0, function* () {
281
+ var _a, _b, _c, _d, _e;
267
282
  // Finish transaction
268
283
  const client = getClientBySocketId(event.socket_id, 'transaction-finish');
269
- if (!client) {
284
+ if (!client || !event.data) {
270
285
  return;
271
286
  }
287
+ const LOG_ACTION = 'socket.transaction.finish';
288
+ const LOG_DETAILS = { ip: event.socket.conn.remoteAddress, uid: (_b = (_a = client.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path: event.data.path };
272
289
  const data = event.data;
273
290
  const tx = client.transactions[data.id];
274
291
  try {
275
292
  if (!tx || data.path !== tx.path) {
276
- throw new Error('transaction_not_found');
293
+ env.log.error(LOG_ACTION, tx ? 'wrong_path' : 'not_found', Object.assign(Object.assign({}, LOG_DETAILS), { id: data.id, tx_path: (_c = tx === null || tx === void 0 ? void 0 : tx.path) !== null && _c !== void 0 ? _c : null }));
294
+ throw new SocketRequestError('transaction_not_found', 'Transaction not found');
277
295
  }
278
296
  clearTimeout(tx.timeout);
279
297
  delete client.transactions[data.id];
280
- if (!env.rules.userHasAccess(client.user, data.path, true)) {
281
- throw new Error('access_denied');
282
- }
283
- const newValue = acebase_core_1.Transport.deserialize(data.value);
284
- try {
285
- yield tx.finish(newValue);
286
- env.debug.verbose(`Transaction ${tx.id} finished`);
287
- serverManager.send(event.socket, 'tx_completed', { id: tx.id });
288
- }
289
- catch (err) {
290
- serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: err.message });
298
+ const access = env.rules.userHasAccess(client.user, data.path, true);
299
+ if (!access.allow) {
300
+ env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_d = access.rulePath) !== null && _d !== void 0 ? _d : null }), access.details);
301
+ throw new SocketRequestError('access_denied', 'Access denied');
291
302
  }
303
+ const newValue = 'val' in data.value ? acebase_core_1.Transport.deserialize(data.value) : undefined;
304
+ const { cursor } = yield tx.finish(newValue);
305
+ env.debug.verbose(`Transaction ${tx.id} finished`);
306
+ serverManager.send(event.socket, 'tx_completed', { id: tx.id, context: { cursor } });
292
307
  }
293
308
  catch (err) {
294
- serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: err.message, data });
309
+ if (!(err instanceof SocketRequestError)) {
310
+ // Other errors have been logged already
311
+ env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
312
+ }
313
+ serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: (_e = err.code) !== null && _e !== void 0 ? _e : err.message, data });
295
314
  tx.finish(); // Finish with undefined, canceling the transaction
296
315
  }
297
316
  }));
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.createServer = exports.SocketIOManager = void 0;
5
- const socketIO = require("socket.io");
6
- const createSocketIOServer = (_a = socketIO.default) !== null && _a !== void 0 ? _a : socketIO; // ESM and CJS compatible approach
4
+ const socket_io_1 = require("socket.io");
5
+ const createSocketIOServer = (httpServer, options) => {
6
+ return new socket_io_1.Server(httpServer, options);
7
+ };
7
8
  const manager_1 = require("./manager");
8
9
  const cors_1 = require("../middleware/cors");
9
10
  class SocketIOManager extends manager_1.WebSocketManager {
@@ -36,14 +37,10 @@ const createServer = (env) => {
36
37
  pingInterval: 5000,
37
38
  pingTimeout: 5000,
38
39
  maxHttpBufferSize: maxPayloadBytes,
39
- // socket.io 2.x:
40
- handlePreflightRequest: (req, res) => {
41
- const headers = (0, cors_1.getCorsHeaders)(env.config.allowOrigin, req.headers.origin);
42
- res.writeHead(200, headers);
43
- res.end();
44
- }
40
+ // Allow socket.io 2.x clients (using engine.io 3.x):
41
+ allowEIO3: true,
45
42
  // socket.io 3+ uses cors package:
46
- // cors: getCorsOptions(env.config.allowOrigin)
43
+ cors: (0, cors_1.getCorsOptions)(env.config.allowOrigin)
47
44
  });
48
45
  // Setup event emitter for communication with consuming server
49
46
  const manager = new SocketIOManager();
@@ -52,7 +49,7 @@ const createServer = (env) => {
52
49
  // Notify manager of new connection
53
50
  manager.emit('connect', { socket, socket_id: socket.id });
54
51
  // Pass any events to manager
55
- socket.on('disconnect', data => manager.emit('disconnect', { socket, socket_id: socket.id, data }));
52
+ socket.on('disconnect', reason => manager.emit('disconnect', { socket, socket_id: socket.id, data: reason }));
56
53
  socket.on('reconnect', data => manager.emit('connect', { socket, socket_id: socket.id, data }));
57
54
  socket.on('signin', accessToken => manager.emit('signin', { socket, socket_id: socket.id, data: { accessToken } }));
58
55
  socket.on('signout', data => manager.emit('signout', { socket, socket_id: socket.id, data }));
@@ -0,0 +1 @@
1
+ export * from '../types';
package/dist/esm/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export { AceBaseServer } from './server.js';
2
2
  export { AceBaseServerTransactionSettings, AceBaseServerAuthenticationSettings } from './settings/index.js';
3
+ export * from './shared/email.js';
4
+ export * from './oauth-providers/index.js';
3
5
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,52 @@
1
+ export class DatabaseLog {
2
+ constructor(logRef) {
3
+ this.logRef = logRef;
4
+ }
5
+ /**
6
+ * Logs an action initiated by a client/user with a positive or negative outcome. Used by `success` and `failure`
7
+ * @param action action identifier
8
+ * @param success whether the action was successful
9
+ * @param details any additional details to be logged
10
+ */
11
+ async event(action, details) {
12
+ await this.logRef?.push({ type: 'event', action, date: new Date(), ...details });
13
+ }
14
+ /**
15
+ * Logs a system warning
16
+ * @param action action identifier
17
+ * @param code warning code
18
+ * @param details any additional details to be logged
19
+ */
20
+ async warning(action, code, details) {
21
+ await this.logRef?.push({ type: 'warning', action, code, date: new Date(), ...details });
22
+ }
23
+ /**
24
+ * Logs a system or client/user error
25
+ * @param action action identifier
26
+ * @param code error code
27
+ * @param details any additional details to be logged
28
+ */
29
+ async error(action, code, details, unexpectedError) {
30
+ const errorDetails = unexpectedError instanceof Error
31
+ ? { error: unexpectedError.stack ?? unexpectedError.message }
32
+ : { error: unexpectedError?.message ?? unexpectedError?.toString() ?? null };
33
+ await this.logRef?.push({ type: 'error', action, code, date: new Date(), ...errorDetails, ...details });
34
+ }
35
+ /**
36
+ * Query the logs
37
+ * @returns
38
+ */
39
+ query() {
40
+ if (!this.logRef) {
41
+ throw new Error('Logging is not enabled');
42
+ }
43
+ return this.logRef.query();
44
+ }
45
+ /**
46
+ * Reference to the logs database collection
47
+ */
48
+ get ref() {
49
+ return this?.logRef;
50
+ }
51
+ }
52
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1,25 @@
1
+ import { sendUnauthorizedError } from "../shared/error.js";
2
+ /**
3
+ * Middleware function that checks if the current user is `admin`. An 403 Forbidden error will be sent in the response if
4
+ * authentication is enabled on the server and the user is not signed in as admin.
5
+ *
6
+ * Can be applied to any route by adding it in the router chain.
7
+ * @example
8
+ * app.get('/endpoint', adminOnly(env), (req, res) => {
9
+ * // If we get here we are either an admin,
10
+ * // or the server doesn't have authentication enabled.
11
+ * })
12
+ * @param env Middle
13
+ * @param errorMessage
14
+ * @returns
15
+ */
16
+ export const adminOnly = (env, errorMessage = 'only admin can perform this operation') => {
17
+ return (req, res, next) => {
18
+ if (env.config.auth.enabled && (!req.user || req.user.uid !== 'admin')) {
19
+ return sendUnauthorizedError(res, 'admin_only', errorMessage);
20
+ }
21
+ next();
22
+ };
23
+ };
24
+ export default adminOnly;
25
+ //# sourceMappingURL=admin-only.js.map
@@ -6,9 +6,9 @@ export const addMiddleware = (env) => {
6
6
  env.app.use(async (req, res, next) => {
7
7
  let authorization = req.get('Authorization');
8
8
  if (typeof authorization !== 'string' && 'auth_token' in req.query) {
9
- // Enables browser calls to be authenticated
10
- if (req.path.startsWith('/export/')) {
11
- // For now, only allow this if the intention is to call '/export' api call
9
+ // Enables browser calls to be authenticated by adding the access token as auth_token query parameter
10
+ if (req.path.startsWith('/export/') || req.path.startsWith('/logs')) {
11
+ // For now, only allow '/export' or '/logs' api calls
12
12
  // In the future, use these prerequisites:
13
13
  // - user must be currently authenticated (in cache)
14
14
  // - ip address must match the token
@@ -29,7 +29,7 @@ export const addMiddleware = (env) => {
29
29
  if (!req.user) {
30
30
  // Query database to get user for this token
31
31
  try {
32
- await signIn({ method: 'private_token', access_token: tokenDetails.access_token }, env, req);
32
+ await signIn({ method: 'internal', access_token: tokenDetails.access_token }, env, req);
33
33
  }
34
34
  catch (err) {
35
35
  return sendNotAuthenticatedError(res, err.code, err.message);
@@ -1,7 +1,8 @@
1
+ import { OAuth2Provider } from "./oauth-provider.js";
1
2
  import { fetch } from '../shared/simple-fetch.js';
2
- export class DropboxAuthProvider {
3
+ export class DropboxAuthProvider extends OAuth2Provider {
3
4
  constructor(settings) {
4
- this.settings = settings;
5
+ super(settings);
5
6
  if (!settings.scopes) {
6
7
  settings.scopes = [];
7
8
  }
@@ -1,7 +1,8 @@
1
+ import { OAuth2Provider } from "./oauth-provider.js";
1
2
  import { fetch } from '../shared/simple-fetch.js';
2
- export class FacebookAuthProvider {
3
+ export class FacebookAuthProvider extends OAuth2Provider {
3
4
  constructor(settings) {
4
- this.settings = settings;
5
+ super(settings);
5
6
  if (!settings.scopes) {
6
7
  settings.scopes = [];
7
8
  }
@@ -1,7 +1,8 @@
1
+ import { OAuth2Provider } from "./oauth-provider.js";
1
2
  import { fetch } from '../shared/simple-fetch.js';
2
- export class GoogleAuthProvider {
3
+ export class GoogleAuthProvider extends OAuth2Provider {
3
4
  constructor(settings) {
4
- this.settings = settings;
5
+ super(settings);
5
6
  if (!settings.scopes) {
6
7
  settings.scopes = [];
7
8
  }
@@ -1,7 +1,8 @@
1
+ import { OAuth2Provider } from "./oauth-provider.js";
1
2
  import { fetch } from '../shared/simple-fetch.js';
2
- export class InstagramAuthProvider {
3
+ export class InstagramAuthProvider extends OAuth2Provider {
3
4
  constructor(settings) {
4
- this.settings = settings;
5
+ super(settings);
5
6
  if (!settings.scopes) {
6
7
  settings.scopes = [];
7
8
  }
@@ -1,2 +1,22 @@
1
- export {};
1
+ // export interface IOAuth2Provider {
2
+ // init(info: OAuth2ProviderInitInfo): Promise<string>;
3
+ // getAccessToken(param: OAuth2ProviderGetAccessTokenParams): Promise<IOAuth2TokenResult>;
4
+ // getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo>;
5
+ // }
6
+ class NotImplementedError extends Error {
7
+ constructor() { super('Not implemented'); }
8
+ }
9
+ export class OAuth2Provider {
10
+ constructor(settings) {
11
+ this.settings = settings;
12
+ }
13
+ init(info) { throw new NotImplementedError(); }
14
+ ;
15
+ getAccessToken(param) { throw new NotImplementedError(); }
16
+ ;
17
+ ;
18
+ getUserInfo(access_token) { throw new NotImplementedError(); }
19
+ ;
20
+ ;
21
+ }
2
22
  //# sourceMappingURL=oauth-provider.js.map
@@ -1,7 +1,8 @@
1
+ import { OAuth2Provider } from "./oauth-provider.js";
1
2
  import { fetch } from '../shared/simple-fetch.js';
2
- export class SpotifyAuthProvider {
3
+ export class SpotifyAuthProvider extends OAuth2Provider {
3
4
  constructor(settings) {
4
- this.settings = settings;
5
+ super(settings);
5
6
  if (!settings.scopes) {
6
7
  settings.scopes = [];
7
8
  }
@@ -12,13 +12,15 @@ export const addRoute = (env) => {
12
12
  env.app.post(`/auth/${env.db.name}/change_password`, async (req, res) => {
13
13
  let access_token = req.user?.access_token;
14
14
  const details = req.body;
15
+ const LOG_ACTION = 'auth.change_password';
16
+ const LOG_DETAILS = { ip: req.ip, uid: details.uid ?? null };
15
17
  if (typeof details !== 'object' || typeof details.uid !== 'string' || typeof details.password !== 'string' || typeof details.new_password !== 'string') {
16
- env.logRef.push({ action: 'change_password', success: false, code: 'invalid_details', ip: req.ip, date: new Date() });
18
+ env.log.error(LOG_ACTION, 'invalid_details', LOG_DETAILS);
17
19
  res.status(400).send('Bad Request'); // Bad Request
18
20
  return;
19
21
  }
20
22
  if (details.new_password.length < 8 || details.new_password.includes(' ') || !/[0-9]/.test(details.new_password) || !/[a-z]/.test(details.new_password) || !/[A-Z]/.test(details.new_password)) {
21
- env.logRef.push({ action: 'change_password', success: false, code: 'new_password_denied', ip: req.ip, date: new Date(), uid: details.uid });
23
+ env.log.error(LOG_ACTION, 'new_password_denied', LOG_DETAILS);
22
24
  const err = 'Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)';
23
25
  res.status(422).send(err); // Unprocessable Entity
24
26
  return;
@@ -53,10 +55,11 @@ export const addRoute = (env) => {
53
55
  publicAccessToken = createPublicAccessToken(user.uid, req.ip, user.access_token, env.tokenSalt);
54
56
  return user; // Update db
55
57
  });
58
+ env.log.event(LOG_ACTION, LOG_DETAILS);
56
59
  res.send({ access_token: publicAccessToken }); // Client must use this new access token from now on
57
60
  }
58
61
  catch (err) {
59
- env.logRef.push({ action: 'change_pwd', success: false, code: err.code, ip: req.ip, date: new Date(), uid: details.uid });
62
+ env.log.error(LOG_ACTION, err.code, LOG_DETAILS);
60
63
  if (err.code) {
61
64
  sendBadRequestError(res, err);
62
65
  }
@@ -8,26 +8,28 @@ export class DeleteError extends Error {
8
8
  export const addRoute = (env) => {
9
9
  env.app.post(`/auth/${env.db.name}/delete`, async (req, res) => {
10
10
  let details = req.body;
11
+ const LOG_ACTION = 'auth.delete';
12
+ const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, delete_uid: details.uid };
11
13
  if (!req.user) {
12
- env.logRef.push({ action: 'delete', success: false, code: 'unauthenticated_delete', delete_uid: details.uid, ip: req.ip, date: new Date() });
14
+ env.log.error(LOG_ACTION, 'unauthenticated_delete', LOG_DETAILS);
13
15
  return sendNotAuthenticatedError(res, 'unauthenticated_delete', 'You are not authorized to perform this operation, your attempt has been logged');
14
16
  }
15
17
  if (req.user.uid !== 'admin' && details.uid !== req.user.uid) {
16
- env.logRef.push({ action: 'delete', success: false, code: 'unauthorized_delete', auth_uid: req.user.uid, delete_uid: details.uid, ip: req.ip, date: new Date() });
18
+ env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
17
19
  return sendUnauthorizedError(res, 'unauthorized_delete', 'You are not authorized to perform this operation, your attempt has been logged');
18
20
  }
19
21
  const uid = details.uid ?? req.user.uid;
20
22
  if (uid === 'admin') {
21
- env.logRef.push({ action: 'delete', success: false, code: 'unauthorized_delete', auth_uid: req.user.uid, delete_uid: details.uid, ip: req.ip, date: new Date() });
23
+ env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
22
24
  return sendUnauthorizedError(res, 'unauthorized_delete', 'The admin account cannot be deleted, your attempt has been logged');
23
25
  }
24
26
  try {
25
27
  await env.authRef.child(uid).remove();
26
- env.logRef.push({ action: 'delete', success: true, auth_uid: req.user.uid, delete_uid: details.uid, ip: req.ip, date: new Date() });
28
+ env.log.event(LOG_ACTION, LOG_DETAILS);
27
29
  res.send('Farewell');
28
30
  }
29
31
  catch (err) {
30
- env.logRef.push({ action: 'delete', success: false, code: 'unexpected', auth_uid: req.user.uid, delete_uid: details.uid, ip: req.ip, date: new Date() });
32
+ env.log.error(LOG_ACTION, 'unexpected', { ...LOG_DETAILS, message: (err instanceof Error && err.message) ?? err.toString() });
31
33
  sendUnexpectedError(res, err);
32
34
  }
33
35
  });
@@ -10,6 +10,8 @@ export class ForgotPasswordError extends Error {
10
10
  export const addRoute = (env) => {
11
11
  env.app.post(`/auth/${env.db.name}/forgot_password`, async (req, res) => {
12
12
  const details = req.body;
13
+ const LOG_ACTION = 'auth.forgot_password';
14
+ const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, email: details.email };
13
15
  try {
14
16
  if (!env.config.email || typeof env.config.email.send !== 'function') {
15
17
  throw new ForgotPasswordError('server_email_config', 'Server email settings have not been configured');
@@ -39,15 +41,15 @@ export const addRoute = (env) => {
39
41
  displayName: user.display_name
40
42
  }
41
43
  };
42
- await Promise.all([
43
- env.config.email.send(request),
44
- snap.ref.update({ password_reset_code: user.password_reset_code })
45
- ]);
46
- env.logRef.push({ action: 'forgot_password', success: true, email: details.email, ip: req.ip, date: new Date() });
44
+ await snap.ref.update({ password_reset_code: user.password_reset_code });
45
+ await env.config.email.send(request).catch(err => {
46
+ env.log.error(LOG_ACTION + '.email', 'unexpected', { ...LOG_DETAILS, request }, err);
47
+ });
48
+ env.log.event(LOG_ACTION, LOG_DETAILS);
47
49
  res.send('OK');
48
50
  }
49
51
  catch (err) {
50
- env.logRef.push({ action: 'forgot_password', success: false, code: err.code || 'unexpected', message: err.code ? null : err.message, email: details.email, ip: req.ip, date: new Date() });
52
+ env.log.error(LOG_ACTION, err.code || 'unexpected', { ...LOG_DETAILS, message: (err instanceof Error && err.message) ?? err.toString() });
51
53
  if (err.code) {
52
54
  sendBadRequestError(res, err);
53
55
  }