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
@@ -25,15 +25,19 @@ exports.VerifyEmailError = VerifyEmailError;
25
25
  * @returns returns the verification function
26
26
  */
27
27
  const addRoute = (env) => {
28
+ const LOG_ACTION = 'auth.verify_email';
28
29
  const verifyEmailAddress = (clientIp, code) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const LOG_DETAILS = { ip: clientIp, uid: null };
29
31
  try {
30
32
  var verification = (0, tokens_1.parseSignedPublicToken)(code, env.tokenSalt);
31
33
  }
32
34
  catch (err) {
33
35
  throw new VerifyEmailError('invalid_code', err.message);
34
36
  }
37
+ LOG_DETAILS.uid = verification.uid;
35
38
  const snap = yield env.authRef.child(verification.uid).get();
36
39
  if (!snap.exists()) {
40
+ env.log.error(LOG_ACTION, 'unknown_user', LOG_DETAILS);
37
41
  throw new VerifyEmailError('unknown_user', 'Unknown user');
38
42
  }
39
43
  const user = snap.val();
@@ -41,21 +45,20 @@ const addRoute = (env) => {
41
45
  // No need to do further checks, code was signed by us so we can trust the contents
42
46
  // Mark account as verified
43
47
  yield snap.ref.update({ email_verified: true });
44
- env.logRef.push({ action: 'verify_email', success: true, ip: clientIp, date: new Date(), uid: user.uid });
48
+ env.log.event(LOG_ACTION, LOG_DETAILS);
45
49
  });
46
50
  env.app.post(`/auth/${env.db.name}/verify_email`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
47
- var _a, _b;
48
51
  const details = req.body;
49
52
  try {
50
53
  yield verifyEmailAddress(req.ip, details.code);
51
54
  res.send('OK');
52
55
  }
53
56
  catch (err) {
54
- env.logRef.push({ action: 'verify_email', success: false, code: err.code, message: err.message, ip: req.ip, date: new Date(), uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null });
55
57
  if (err.code) {
56
58
  (0, error_1.sendBadRequestError)(res, err);
57
59
  }
58
60
  else {
61
+ env.log.error(LOG_ACTION, 'unexpected', { ip: req.ip, message: err.message, verificaion_code: details.code });
59
62
  (0, error_1.sendUnexpectedError)(res, err);
60
63
  }
61
64
  }
@@ -10,12 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
+ const admin_only_1 = require("../middleware/admin-only");
13
14
  const error_1 = require("../shared/error");
14
15
  const addRoute = (env) => {
15
16
  const handleRequest = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
- if (!req.user || req.user.username !== 'admin') {
17
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform index operations');
18
- }
19
17
  try {
20
18
  const data = req.body;
21
19
  yield env.db.indexes.create(data.path, data.key, data.options);
@@ -26,7 +24,7 @@ const addRoute = (env) => {
26
24
  (0, error_1.sendError)(res, err);
27
25
  }
28
26
  });
29
- env.app.post(`/index/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
27
+ env.app.post(`/index/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
30
28
  var _a;
31
29
  // Legacy endpoint that was designed to handle multiple actions
32
30
  // The only action ever implemented was 'create', so we'll handle that here
@@ -35,7 +33,7 @@ const addRoute = (env) => {
35
33
  }
36
34
  handleRequest(req, res);
37
35
  }));
38
- env.app.post(`/index/${env.db.name}/create`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
36
+ env.app.post(`/index/${env.db.name}/create`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
39
37
  // New dedicated create endpoint
40
38
  handleRequest(req, res);
41
39
  }));
@@ -10,13 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
+ const admin_only_1 = require("../middleware/admin-only");
13
14
  const error_1 = require("../shared/error");
14
15
  const addRoute = (env) => {
15
- env.app.post(`/index/${env.db.name}/delete`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ env.app.post(`/index/${env.db.name}/delete`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
17
  // Delete an index
17
- if (!req.user || req.user.username !== 'admin') {
18
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform index operations');
19
- }
20
18
  try {
21
19
  const data = req.body;
22
20
  if (!data.fileName) {
@@ -10,14 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
+ const admin_only_1 = require("../middleware/admin-only");
13
14
  const error_1 = require("../shared/error");
14
15
  ;
15
16
  const addRoute = (env) => {
16
- env.app.get(`/index/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
+ env.app.get(`/index/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
18
  // Get all indexes
18
- if (!req.user || req.user.username !== 'admin') {
19
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform index operations');
20
- }
21
19
  try {
22
20
  const indexes = yield env.db.indexes.get();
23
21
  res.contentType('application/json').send(indexes.map(index => {
@@ -14,17 +14,15 @@ const acebase_core_1 = require("acebase-core");
14
14
  const error_1 = require("../shared/error");
15
15
  const addRoute = (env) => {
16
16
  env.app.get(`/reflect/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
+ var _a;
17
18
  // Reflection API
18
- // if (!req.user || req.user.username !== 'admin') {
19
- // return sendUnauthorizedError(res, 'admin_only', 'only admin can use reflection api');
20
- // }
21
19
  const path = req.path.slice(env.db.name.length + 10);
22
20
  const access = env.rules.userHasAccess(req.user, path, false);
23
21
  if (!access.allow) {
24
22
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
25
23
  }
26
24
  const impersonatedAccess = {
27
- uid: (!req.user || req.user.username !== 'admin') ? null : req.query.impersonate,
25
+ uid: ((_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== 'admin' ? null : req.query.impersonate,
28
26
  read: {
29
27
  allow: false,
30
28
  error: null
@@ -10,13 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
+ const admin_only_1 = require("../middleware/admin-only");
13
14
  const error_1 = require("../shared/error");
14
15
  const addRoute = (env) => {
15
- env.app.get(`/schema/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ env.app.get(`/schema/${env.db.name}/*`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
17
  // Get defined schema for a specifc path
17
- if (!req.user || req.user.username !== 'admin') {
18
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform schema operations');
19
- }
20
18
  try {
21
19
  const path = req.path.slice(env.db.name.length + 9);
22
20
  const schema = yield env.db.schema.get(path);
@@ -10,13 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
+ const admin_only_1 = require("../middleware/admin-only");
13
14
  const error_1 = require("../shared/error");
14
15
  const addRoute = (env) => {
15
- env.app.post(`/schema/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ env.app.post(`/schema/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
17
  // defines a schema
17
- if (!req.user || req.user.username !== 'admin') {
18
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform schema operations');
19
- }
20
18
  try {
21
19
  const data = req.body;
22
20
  const { path, schema } = data;
@@ -11,14 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
13
  const acebase_core_1 = require("acebase-core");
14
+ const admin_only_1 = require("../middleware/admin-only");
14
15
  const error_1 = require("../shared/error");
15
16
  const addRoute = (env) => {
16
- env.app.post(`/schema/${env.db.name}/test`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
+ env.app.post(`/schema/${env.db.name}/test`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
18
  var _a, _b;
18
19
  // tests a schema
19
- if (!req.user || req.user.username !== 'admin') {
20
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform schema operations');
21
- }
22
20
  try {
23
21
  const data = req.body;
24
22
  if (typeof ((_a = data.value) === null || _a === void 0 ? void 0 : _a.val) === 'undefined' || !['string', 'object', 'undefined'].includes(typeof ((_b = data.value) === null || _b === void 0 ? void 0 : _b.map))) {
@@ -10,13 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
+ const admin_only_1 = require("../middleware/admin-only");
13
14
  const error_1 = require("../shared/error");
14
15
  const addRoute = (env) => {
15
- env.app.get(`/schema/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ env.app.get(`/schema/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
17
  // Get all defined schemas
17
- if (!req.user || req.user.username !== 'admin') {
18
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform schema operations');
19
- }
20
18
  try {
21
19
  const schemas = yield env.db.schema.all();
22
20
  res.contentType('application/json').send(schemas.map(schema => ({
@@ -22,11 +22,13 @@ class SetDataError extends Error {
22
22
  exports.SetDataError = SetDataError;
23
23
  const addRoute = (env) => {
24
24
  env.app.put(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
25
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
26
- // Set data
25
+ var _a, _b, _c, _d, _e, _f;
27
26
  const path = req.path.slice(env.db.name.length + 7);
27
+ const LOG_ACTION = 'data.set';
28
+ const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path };
28
29
  const access = env.rules.userHasAccess(req.user, path, true);
29
30
  if (!access.allow) {
31
+ 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, rule_error: (_e = (_d = access.details) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : null }));
30
32
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
31
33
  }
32
34
  try {
@@ -35,7 +37,7 @@ const addRoute = (env) => {
35
37
  throw new SetDataError('invalid_serialized_value', 'The sent value is not properly serialized');
36
38
  }
37
39
  const val = acebase_core_1.Transport.deserialize(data);
38
- if (path === '' && ((_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== 'admin' && val !== null && typeof val === 'object') {
40
+ if (path === '' && ((_f = req.user) === null || _f === void 0 ? void 0 : _f.uid) !== 'admin' && val !== null && typeof val === 'object') {
39
41
  // Non-admin user: remove any private properties from the update object
40
42
  Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
41
43
  }
@@ -47,24 +49,26 @@ const addRoute = (env) => {
47
49
  yield env.db.ref(path)
48
50
  .context(req.context)
49
51
  .set(val);
52
+ // NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
53
+ const returnContext = { acebase_cursor: req.context.acebase_cursor };
54
+ res.setHeader('AceBase-Context', JSON.stringify(returnContext));
50
55
  res.send({ success: true });
51
56
  }
52
57
  catch (err) {
53
58
  if (err instanceof acebase_1.SchemaValidationError) {
54
- (_b = env.logRef) === null || _b === void 0 ? void 0 : _b.push({ action: 'set_data', success: false, code: 'schema_validation_failed', path, error: err.reason, ip: req.ip, uid: (_d = (_c = req.user) === null || _c === void 0 ? void 0 : _c.uid) !== null && _d !== void 0 ? _d : null });
59
+ env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
55
60
  res.status(422).send({ code: 'schema_validation_failed', message: err.message });
56
61
  }
57
62
  else if (err instanceof SetDataError) {
58
- (_e = env.logRef) === null || _e === void 0 ? void 0 : _e.push({ action: 'set_data', success: false, code: err.code, path, ip: req.ip, uid: (_g = (_f = req.user) === null || _f === void 0 ? void 0 : _f.uid) !== null && _g !== void 0 ? _g : null });
63
+ env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
59
64
  (0, error_1.sendBadRequestError)(res, err);
60
65
  }
61
66
  else {
62
67
  env.debug.error(`failed to set "${path}":`, err);
63
- (_h = env.logRef) === null || _h === void 0 ? void 0 : _h.push({ action: 'set_data', success: false, code: 'unknown_error', path, error: err.message, ip: req.ip, uid: (_k = (_j = req.user) === null || _j === void 0 ? void 0 : _j.uid) !== null && _k !== void 0 ? _k : null });
68
+ env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
64
69
  (0, error_1.sendError)(res, err);
65
70
  }
66
71
  }
67
- ;
68
72
  }));
69
73
  };
70
74
  exports.addRoute = addRoute;
@@ -27,8 +27,11 @@ const addRoutes = (env) => {
27
27
  env.app.post(`/transaction/${env.db.name}/start`, (req, res) => {
28
28
  var _a, _b, _c, _d;
29
29
  const data = req.body;
30
+ const LOG_ACTION = 'data.transaction.start';
31
+ const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path: data.path };
30
32
  const access = env.rules.userHasAccess(req.user, data.path, true);
31
33
  if (!access.allow) {
34
+ 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);
32
35
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
33
36
  }
34
37
  // Start transaction
@@ -64,16 +67,19 @@ const addRoutes = (env) => {
64
67
  }
65
68
  catch (err) {
66
69
  env.debug.error(`failed to start transaction on "${tx.path}":`, err);
67
- (_a = env.logRef) === null || _a === void 0 ? void 0 : _a.push({ action: 'tx_start', success: false, code: (_b = err.code) !== null && _b !== void 0 ? _b : 'unknown_error', path: tx.path, error: err.message, ip: req.ip, uid: (_d = (_c = req.user) === null || _c === void 0 ? void 0 : _c.uid) !== null && _d !== void 0 ? _d : null });
70
+ env.log.error(LOG_ACTION, (_d = err.code) !== null && _d !== void 0 ? _d : 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
68
71
  (0, error_1.sendUnexpectedError)(res, err);
69
72
  }
70
73
  });
71
74
  // Finish transaction endpoint:
72
75
  env.app.post(`/transaction/${env.db.name}/finish`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
73
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
76
+ var _a, _b, _c, _d, _e, _f, _g;
74
77
  const data = req.body;
78
+ const LOG_ACTION = 'data.transaction.finish';
79
+ const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path: data.path };
75
80
  const tx = _transactions.get(data.id);
76
81
  if (!tx || tx.path !== data.path) {
82
+ 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 }));
77
83
  res.statusCode = 410; // Gone
78
84
  res.send(`transaction not found`);
79
85
  return;
@@ -82,34 +88,48 @@ const addRoutes = (env) => {
82
88
  _transactions.delete(tx.id);
83
89
  const access = env.rules.userHasAccess(req.user, tx.path, true);
84
90
  if (!access.allow) {
91
+ 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);
85
92
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
86
93
  }
87
94
  // Finish transaction
88
95
  try {
89
- if (typeof ((_a = data.value) === null || _a === void 0 ? void 0 : _a.val) === 'undefined' || !['string', 'object', 'undefined'].includes(typeof ((_b = data.value) === null || _b === void 0 ? void 0 : _b.map))) {
96
+ let cancel = false;
97
+ if (typeof data.value === 'object' && (data.value === null || Object.keys(data.value).length === 0)) {
98
+ // Returning undefined from a transaction callback should cancel the transaction
99
+ // acebase-client (Transport.serialize) serializes value undefined as { val: undefined, map: undefined }, which
100
+ // then is sent to the server as an empty object: {}
101
+ cancel = true;
102
+ }
103
+ else if (typeof ((_e = data.value) === null || _e === void 0 ? void 0 : _e.val) === 'undefined' || !['string', 'object', 'undefined'].includes(typeof ((_f = data.value) === null || _f === void 0 ? void 0 : _f.map))) {
90
104
  throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
91
105
  }
92
- const newValue = acebase_core_1.Transport.deserialize(data.value);
93
- if (tx.path === '' && ((_c = req.user) === null || _c === void 0 ? void 0 : _c.uid) !== 'admin' && newValue !== null && typeof newValue === 'object') {
106
+ const newValue = cancel ? undefined : acebase_core_1.Transport.deserialize(data.value);
107
+ if (tx.path === '' && ((_g = req.user) === null || _g === void 0 ? void 0 : _g.uid) !== 'admin' && newValue !== null && typeof newValue === 'object') {
94
108
  // Non-admin user: remove any private properties from the update object
95
109
  Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
96
110
  }
97
- yield tx.finish(newValue);
111
+ const result = yield tx.finish(newValue);
112
+ // NEW: capture cursor and return it in the response context header
113
+ if (!tx.context) {
114
+ tx.context = {};
115
+ }
116
+ tx.context.acebase_cursor = result.cursor;
117
+ res.setHeader('AceBase-Context', JSON.stringify(tx.context));
98
118
  res.send('done');
99
119
  }
100
120
  catch (err) {
101
121
  tx.finish(); // Finish without value cancels the transaction
102
122
  if (err instanceof acebase_1.SchemaValidationError) {
103
- (_d = env.logRef) === null || _d === void 0 ? void 0 : _d.push({ action: 'tx_finish', success: false, code: 'schema_validation_failed', path: tx.path, error: err.reason, ip: req.ip, uid: (_f = (_e = req.user) === null || _e === void 0 ? void 0 : _e.uid) !== null && _f !== void 0 ? _f : null });
123
+ env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
104
124
  res.status(422).send({ code: 'schema_validation_failed', message: err.message });
105
125
  }
106
126
  else if (err instanceof DataTransactionError) {
107
- (_g = env.logRef) === null || _g === void 0 ? void 0 : _g.push({ action: 'tx_finish', success: false, code: err.code, path: tx.path, ip: req.ip, uid: (_j = (_h = req.user) === null || _h === void 0 ? void 0 : _h.uid) !== null && _j !== void 0 ? _j : null });
127
+ env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
108
128
  (0, error_1.sendBadRequestError)(res, err);
109
129
  }
110
130
  else {
111
- env.debug.error(`failed to finsih transaction on "${tx.path}":`, err);
112
- (_k = env.logRef) === null || _k === void 0 ? void 0 : _k.push({ action: 'tx_finish', success: false, code: 'unknown_error', path: tx.path, error: err.message, ip: req.ip, uid: (_m = (_l = req.user) === null || _l === void 0 ? void 0 : _l.uid) !== null && _m !== void 0 ? _m : null });
131
+ env.debug.error(`failed to finish transaction on "${tx.path}":`, err);
132
+ env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
113
133
  (0, error_1.sendError)(res, err);
114
134
  }
115
135
  }
@@ -22,11 +22,13 @@ class UpdateDataError extends Error {
22
22
  exports.UpdateDataError = UpdateDataError;
23
23
  const addRoute = (env) => {
24
24
  env.app.post(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
25
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
26
- // update data
25
+ var _a, _b, _c, _d, _e, _f;
27
26
  const path = req.path.slice(env.db.name.length + 7);
27
+ const LOG_ACTION = 'data.update';
28
+ const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path };
28
29
  const access = env.rules.userHasAccess(req.user, path, true);
29
30
  if (!access.allow) {
31
+ 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, rule_error: (_e = (_d = access.details) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : null }));
30
32
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
31
33
  }
32
34
  try {
@@ -35,7 +37,7 @@ const addRoute = (env) => {
35
37
  throw new UpdateDataError('invalid_serialized_value', 'The sent value is not properly serialized');
36
38
  }
37
39
  const val = acebase_core_1.Transport.deserialize(data);
38
- if (path === '' && ((_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== 'admin' && val !== null && typeof val === 'object') {
40
+ if (path === '' && ((_f = req.user) === null || _f === void 0 ? void 0 : _f.uid) !== 'admin' && val !== null && typeof val === 'object') {
39
41
  // Non-admin user: remove any private properties from the update object
40
42
  Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
41
43
  }
@@ -47,20 +49,23 @@ const addRoute = (env) => {
47
49
  yield env.db.ref(path)
48
50
  .context(req.context)
49
51
  .update(val);
52
+ // NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
53
+ const returnContext = { acebase_cursor: req.context.acebase_cursor };
54
+ res.setHeader('AceBase-Context', JSON.stringify(returnContext));
50
55
  res.send({ success: true });
51
56
  }
52
57
  catch (err) {
53
58
  if (err instanceof acebase_1.SchemaValidationError) {
54
- (_b = env.logRef) === null || _b === void 0 ? void 0 : _b.push({ action: 'update_data', success: false, code: 'schema_validation_failed', path, error: err.reason, ip: req.ip, uid: (_d = (_c = req.user) === null || _c === void 0 ? void 0 : _c.uid) !== null && _d !== void 0 ? _d : null });
59
+ env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
55
60
  res.status(422).send({ code: 'schema_validation_failed', message: err.message });
56
61
  }
57
62
  else if (err instanceof UpdateDataError) {
58
- (_e = env.logRef) === null || _e === void 0 ? void 0 : _e.push({ action: 'update_data', success: false, code: err.code, path, ip: req.ip, uid: (_g = (_f = req.user) === null || _f === void 0 ? void 0 : _f.uid) !== null && _g !== void 0 ? _g : null });
63
+ env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
59
64
  (0, error_1.sendBadRequestError)(res, err);
60
65
  }
61
66
  else {
62
67
  env.debug.error(`failed to update "${path}":`, err);
63
- (_h = env.logRef) === null || _h === void 0 ? void 0 : _h.push({ action: 'update_data', success: false, code: `unknown_error`, path, error: err.message, ip: req.ip, uid: (_k = (_j = req.user) === null || _j === void 0 ? void 0 : _j.uid) !== null && _k !== void 0 ? _k : null });
68
+ env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
64
69
  (0, error_1.sendError)(res, err);
65
70
  }
66
71
  }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addRoute = void 0;
13
+ const admin_only_1 = require("../middleware/admin-only");
14
+ const addRoute = (env) => {
15
+ env.app.get(`/logs/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ // Get database logs
17
+ var _a, _b, _c;
18
+ // Create indexes if not there yet
19
+ const db = env.log.ref.db;
20
+ const createIndexes = [
21
+ db.indexes.create(env.log.ref.path, 'date')
22
+ ];
23
+ if (req.query.filter_col === 'action') {
24
+ createIndexes.push(db.indexes.create(env.log.ref.path, 'action', { include: ['date'] }));
25
+ }
26
+ if (req.query.filter_col === 'code') {
27
+ createIndexes.push(db.indexes.create(env.log.ref.path, 'code', { include: ['date'] }));
28
+ }
29
+ yield Promise.all(createIndexes);
30
+ try {
31
+ const query = env.log.query()
32
+ .take(parseInt((_a = req.query.take) !== null && _a !== void 0 ? _a : '100'))
33
+ .skip(parseInt((_b = req.query.skip) !== null && _b !== void 0 ? _b : '0'))
34
+ .sort((_c = req.query.sort) !== null && _c !== void 0 ? _c : 'date', false);
35
+ if (req.query.filter_col) {
36
+ query.filter(req.query.filter_col, req.query.filter_op, req.query.filter_val);
37
+ }
38
+ const snaps = yield query.get();
39
+ const logs = snaps.getValues();
40
+ res.send(logs);
41
+ }
42
+ catch (err) {
43
+ res.statusCode = 500;
44
+ res.send(err.message);
45
+ }
46
+ }));
47
+ };
48
+ exports.addRoute = addRoute;
49
+ exports.default = exports.addRoute;
50
+ //# sourceMappingURL=meta-logs.js.map
@@ -4,6 +4,7 @@ exports.addRoutes = void 0;
4
4
  const meta_info_1 = require("./meta-info");
5
5
  const meta_ping_1 = require("./meta-ping");
6
6
  const meta_stats_1 = require("./meta-stats");
7
+ const meta_logs_1 = require("./meta-logs");
7
8
  const addRoutes = (env) => {
8
9
  // Add info endpoint
9
10
  (0, meta_info_1.default)(env);
@@ -11,6 +12,8 @@ const addRoutes = (env) => {
11
12
  (0, meta_ping_1.default)(env);
12
13
  // Add database stats endpoint
13
14
  (0, meta_stats_1.default)(env);
15
+ // Add logs endpoint (admin only)
16
+ (0, meta_logs_1.default)(env);
14
17
  };
15
18
  exports.addRoutes = addRoutes;
16
19
  exports.default = exports.addRoutes;
@@ -18,8 +18,10 @@ const socketSignInSuccess = `<html><script>window.close()</script><body>Signed i
18
18
  const socketSignInFailed = `<html><script>window.close()</script><body>Failed to sign in. You can <a href="javascript:window.close()">close</a> this page</body></html>`;
19
19
  const addRoute = (env) => {
20
20
  env.app.get(`/oauth2/${env.db.name}/signin`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
21
- var _a, _b;
22
21
  // This is where the user is redirected to by the provider after signin or error
22
+ var _a, _b;
23
+ const LOG_ACTION = 'oauth2.signin';
24
+ const LOG_DETAILS = { ip: req.ip, provider: null };
23
25
  try {
24
26
  const state = (0, tokens_1.parseSignedPublicToken)(req.query.state, env.tokenSalt);
25
27
  if (req.query.error) {
@@ -36,6 +38,7 @@ const addRoute = (env) => {
36
38
  // Got authorization code
37
39
  const authCode = req.query.code;
38
40
  const provider = env.authProviders[state.provider];
41
+ LOG_DETAILS.provider = state.provider;
39
42
  // Get access & refresh tokens
40
43
  const tokens = yield provider.getAccessToken({ type: 'auth', auth_code: authCode, redirect_url: `${req.protocol}://${req.headers.host}/oauth2/${env.db.name}/signin` });
41
44
  let user_details;
@@ -55,12 +58,13 @@ const addRoute = (env) => {
55
58
  if (contentType === 'image/png') { //state.provider === 'google' &&
56
59
  // Don't accept image/png, because it's probably a placeholder image. Google does this by creating a png with people's initials
57
60
  user_details.picture = [];
58
- return;
59
61
  }
60
- const image = yield response.arrayBuffer();
61
- let buff = Buffer.from(image);
62
- best.url = `data:${contentType};base64,${buff.toString('base64')}`;
63
- user_details.picture = [best]; // Only keep the best one
62
+ else {
63
+ const image = yield response.arrayBuffer();
64
+ let buff = Buffer.from(image);
65
+ best.url = `data:${contentType};base64,${buff.toString('base64')}`;
66
+ user_details.picture = [best]; // Only keep the best one
67
+ }
64
68
  }
65
69
  catch (err) {
66
70
  env.debug.warn(`Could not fetch profile picture from "${best.url}": `, err);
@@ -141,7 +145,7 @@ const addRoute = (env) => {
141
145
  // Add provider details
142
146
  yield env.authRef.child(uid).child('settings').update(getProviderSettings());
143
147
  // Log success
144
- env.logRef.push({ action: 'oauth2_signin', success: true, ip: req.ip, date: new Date(), uid });
148
+ env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { uid }));
145
149
  // Cache the user
146
150
  env.authCache.set(user.uid, user);
147
151
  // Request signin e-mail to be sent
@@ -161,13 +165,13 @@ const addRoute = (env) => {
161
165
  provider: state.provider
162
166
  };
163
167
  (_a = env.config.email) === null || _a === void 0 ? void 0 : _a.send(request).catch(err => {
164
- env.logRef.push({ action: 'oauth2_login_email', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, request });
168
+ env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { uid, request }), err);
165
169
  });
166
170
  }
167
171
  else if (snaps.length === 0) {
168
172
  // User does not exist, create
169
173
  if (!env.config.auth.allowUserSignup) {
170
- env.logRef.push({ action: 'oauth2_signup', success: false, code: 'user_signup_disabled', provider: state.provider, email: user_details.email, date: new Date() });
174
+ env.log.error(LOG_ACTION, 'user_signup_disabled', Object.assign(Object.assign({}, LOG_DETAILS), { email: user_details.email }));
171
175
  res.statusCode = 403; // Forbidden
172
176
  return res.send({ code: 'admin_only', message: 'Only admin is allowed to create users' });
173
177
  }
@@ -194,7 +198,7 @@ const addRoute = (env) => {
194
198
  const uid = userRef.key;
195
199
  user.uid = uid;
196
200
  // Log success
197
- env.logRef.push({ action: 'oauth2_signup', success: true, ip: req.ip, date: new Date(), uid });
201
+ env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { uid }));
198
202
  // Cache the user
199
203
  env.authCache.set(user.uid, user);
200
204
  // Request welcome e-mail to be sent
@@ -214,7 +218,7 @@ const addRoute = (env) => {
214
218
  provider: state.provider
215
219
  };
216
220
  (_b = env.config.email) === null || _b === void 0 ? void 0 : _b.send(request).catch(err => {
217
- env.logRef.push({ action: 'oauth2_signup_email', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, request });
221
+ env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { uid, request }), err);
218
222
  });
219
223
  }
220
224
  else {
package/dist/cjs/rules.js CHANGED
@@ -64,11 +64,11 @@ class PathBasedRules {
64
64
  rule.getText = () => {
65
65
  return text;
66
66
  };
67
- parent[key] = rule;
67
+ return parent[key] = rule;
68
68
  }
69
69
  else if (key === '.schema') {
70
70
  // Add schema
71
- env.db.schema.set(path, rule)
71
+ return env.db.schema.set(path, rule)
72
72
  .catch(err => {
73
73
  env.debug.error(`Error parsing ${path}/.schema: ${err.message}`);
74
74
  });
@@ -83,15 +83,15 @@ class PathBasedRules {
83
83
  };
84
84
  processRules('', accessRules.rules, []);
85
85
  // Watch file for changes
86
- const wacthFileListener = () => {
86
+ const watchFileListener = () => {
87
87
  // Reload access rules
88
88
  const accessRules = readRules();
89
89
  processRules('', accessRules, []);
90
90
  this.accessRules = accessRules;
91
91
  };
92
- fs.watchFile(rulesFilePath, wacthFileListener);
92
+ fs.watchFile(rulesFilePath, watchFileListener);
93
93
  this.stop = () => {
94
- fs.unwatchFile(rulesFilePath, wacthFileListener);
94
+ fs.unwatchFile(rulesFilePath, watchFileListener);
95
95
  };
96
96
  process.on('SIGINT', this.stop);
97
97
  this.authEnabled = env.authEnabled;