acebase-server 1.15.1 → 1.16.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 (503) hide show
  1. package/.eslintrc.json +49 -0
  2. package/README.md +10 -0
  3. package/dist/cjs/auth.js +2 -2
  4. package/dist/cjs/cluster.js +2 -2
  5. package/dist/cjs/middleware/cors.js +3 -3
  6. package/dist/cjs/oauth-providers/dropbox.js +22 -22
  7. package/dist/cjs/oauth-providers/facebook.js +16 -16
  8. package/dist/cjs/oauth-providers/google.js +33 -39
  9. package/dist/cjs/oauth-providers/index.js +1 -1
  10. package/dist/cjs/oauth-providers/instagram.js +12 -12
  11. package/dist/cjs/oauth-providers/oauth-provider.js +0 -5
  12. package/dist/cjs/oauth-providers/spotify.js +34 -34
  13. package/dist/cjs/routes/auth-change-password.js +5 -5
  14. package/dist/cjs/routes/auth-delete.js +1 -1
  15. package/dist/cjs/routes/auth-forgot-password.js +2 -2
  16. package/dist/cjs/routes/auth-reset-password.js +11 -9
  17. package/dist/cjs/routes/auth-signin.js +1 -1
  18. package/dist/cjs/routes/auth-signout.js +1 -1
  19. package/dist/cjs/routes/auth-signup.js +5 -5
  20. package/dist/cjs/routes/auth-update.js +1 -1
  21. package/dist/cjs/routes/auth-verify-email.js +8 -6
  22. package/dist/cjs/routes/auth.js +1 -1
  23. package/dist/cjs/routes/data-export.js +1 -1
  24. package/dist/cjs/routes/data-get.js +2 -2
  25. package/dist/cjs/routes/data-index-list.js +0 -1
  26. package/dist/cjs/routes/data-query.js +1 -1
  27. package/dist/cjs/routes/data-reflect.js +4 -4
  28. package/dist/cjs/routes/data-schema-get.js +1 -1
  29. package/dist/cjs/routes/data-schemas-list.js +1 -1
  30. package/dist/cjs/routes/data-transaction.js +1 -1
  31. package/dist/cjs/routes/docs.js +57 -54
  32. package/dist/cjs/routes/meta-info.js +8 -12
  33. package/dist/cjs/routes/meta-logs.js +1 -1
  34. package/dist/cjs/routes/oauth2-init.js +8 -5
  35. package/dist/cjs/routes/oauth2-refresh.js +2 -2
  36. package/dist/cjs/routes/oauth2-signin.js +23 -23
  37. package/dist/cjs/routes/webmanager.js +4 -4
  38. package/dist/cjs/rules.js +8 -8
  39. package/dist/cjs/schema/user.js +1 -2
  40. package/dist/cjs/server.js +74 -31
  41. package/dist/cjs/settings/email.js +0 -2
  42. package/dist/cjs/settings/index.js +19 -4
  43. package/dist/cjs/shared/email.js +0 -4
  44. package/dist/cjs/shared/env.js +0 -2
  45. package/dist/cjs/shared/error.js +0 -1
  46. package/dist/cjs/shared/http.js +9 -1
  47. package/dist/cjs/shared/password.js +5 -5
  48. package/dist/cjs/shared/rootpath.js +1 -1
  49. package/dist/cjs/shared/signin.js +3 -3
  50. package/dist/cjs/shared/simple-fetch.js +5 -5
  51. package/dist/cjs/shared/tokens.js +3 -3
  52. package/dist/cjs/start.js +6 -6
  53. package/dist/cjs/websocket/index.js +11 -11
  54. package/dist/cjs/websocket/socket.io.js +2 -1
  55. package/dist/esm/auth.js +5 -5
  56. package/dist/esm/cluster.js +2 -2
  57. package/dist/esm/middleware/admin-only.js +1 -1
  58. package/dist/esm/middleware/cors.js +3 -3
  59. package/dist/esm/middleware/user.js +3 -3
  60. package/dist/esm/oauth-providers/dropbox.js +47 -51
  61. package/dist/esm/oauth-providers/facebook.js +34 -38
  62. package/dist/esm/oauth-providers/google.js +33 -39
  63. package/dist/esm/oauth-providers/index.js +1 -1
  64. package/dist/esm/oauth-providers/instagram.js +28 -32
  65. package/dist/esm/oauth-providers/oauth-provider.js +0 -5
  66. package/dist/esm/oauth-providers/spotify.js +46 -52
  67. package/dist/esm/routes/auth-change-password.js +5 -5
  68. package/dist/esm/routes/auth-delete.js +1 -1
  69. package/dist/esm/routes/auth-forgot-password.js +2 -2
  70. package/dist/esm/routes/auth-reset-password.js +11 -9
  71. package/dist/esm/routes/auth-signin.js +1 -1
  72. package/dist/esm/routes/auth-signout.js +1 -1
  73. package/dist/esm/routes/auth-signup.js +5 -5
  74. package/dist/esm/routes/auth-update.js +1 -1
  75. package/dist/esm/routes/auth-verify-email.js +8 -6
  76. package/dist/esm/routes/auth.js +1 -1
  77. package/dist/esm/routes/data-export.js +1 -1
  78. package/dist/esm/routes/data-get.js +2 -2
  79. package/dist/esm/routes/data-index-list.js +0 -1
  80. package/dist/esm/routes/data-query.js +1 -1
  81. package/dist/esm/routes/data-reflect.js +4 -4
  82. package/dist/esm/routes/data-schema-get.js +1 -1
  83. package/dist/esm/routes/data-schemas-list.js +1 -1
  84. package/dist/esm/routes/data-transaction.js +1 -1
  85. package/dist/esm/routes/data.js +1 -1
  86. package/dist/esm/routes/docs.js +56 -54
  87. package/dist/esm/routes/meta-info.js +8 -12
  88. package/dist/esm/routes/meta-logs.js +1 -1
  89. package/dist/esm/routes/oauth2-init.js +8 -5
  90. package/dist/esm/routes/oauth2-refresh.js +2 -2
  91. package/dist/esm/routes/oauth2-signin.js +20 -20
  92. package/dist/esm/routes/webmanager.js +5 -5
  93. package/dist/esm/rules.js +8 -8
  94. package/dist/esm/schema/user.js +1 -2
  95. package/dist/esm/server.js +72 -30
  96. package/dist/esm/settings/email.js +0 -2
  97. package/dist/esm/settings/index.js +19 -4
  98. package/dist/esm/shared/email.js +0 -4
  99. package/dist/esm/shared/env.js +0 -2
  100. package/dist/esm/shared/error.js +0 -1
  101. package/dist/esm/shared/http.js +7 -0
  102. package/dist/esm/shared/password.js +5 -5
  103. package/dist/esm/shared/rootpath.js +2 -2
  104. package/dist/esm/shared/signin.js +6 -6
  105. package/dist/esm/shared/simple-fetch.js +5 -5
  106. package/dist/esm/shared/tokens.js +3 -3
  107. package/dist/esm/start.js +6 -6
  108. package/dist/esm/websocket/index.js +15 -15
  109. package/dist/esm/websocket/manager.js +1 -1
  110. package/dist/esm/websocket/socket.io.js +2 -1
  111. package/dist/types/auth.d.ts +1 -1
  112. package/dist/types/logger.d.ts +1 -1
  113. package/dist/types/middleware/404.d.ts +1 -1
  114. package/dist/types/middleware/admin-only.d.ts +3 -3
  115. package/dist/types/middleware/cache.d.ts +1 -1
  116. package/dist/types/middleware/context.d.ts +1 -1
  117. package/dist/types/middleware/cors.d.ts +1 -1
  118. package/dist/types/middleware/swagger.d.ts +1 -1
  119. package/dist/types/middleware/user.d.ts +1 -1
  120. package/dist/types/oauth-providers/dropbox.d.ts +1 -1
  121. package/dist/types/oauth-providers/facebook.d.ts +1 -1
  122. package/dist/types/oauth-providers/google.d.ts +1 -1
  123. package/dist/types/oauth-providers/instagram.d.ts +1 -1
  124. package/dist/types/oauth-providers/spotify.d.ts +1 -1
  125. package/dist/types/routes/auth-change-password.d.ts +2 -2
  126. package/dist/types/routes/auth-delete.d.ts +2 -2
  127. package/dist/types/routes/auth-forgot-password.d.ts +2 -2
  128. package/dist/types/routes/auth-reset-password.d.ts +2 -2
  129. package/dist/types/routes/auth-signin.d.ts +2 -2
  130. package/dist/types/routes/auth-signout.d.ts +2 -2
  131. package/dist/types/routes/auth-signup.d.ts +2 -2
  132. package/dist/types/routes/auth-state.d.ts +3 -3
  133. package/dist/types/routes/auth-update.d.ts +2 -2
  134. package/dist/types/routes/auth-verify-email.d.ts +2 -2
  135. package/dist/types/routes/data-exists.d.ts +1 -1
  136. package/dist/types/routes/data-export.d.ts +1 -1
  137. package/dist/types/routes/data-get.d.ts +1 -1
  138. package/dist/types/routes/data-import.d.ts +1 -1
  139. package/dist/types/routes/data-index-create.d.ts +2 -2
  140. package/dist/types/routes/data-index-delete.d.ts +1 -1
  141. package/dist/types/routes/data-index-list.d.ts +2 -2
  142. package/dist/types/routes/data-query.d.ts +1 -1
  143. package/dist/types/routes/data-reflect.d.ts +1 -1
  144. package/dist/types/routes/data-schema-get.d.ts +1 -1
  145. package/dist/types/routes/data-schema-set.d.ts +1 -1
  146. package/dist/types/routes/data-schema-test.d.ts +1 -1
  147. package/dist/types/routes/data-schemas-list.d.ts +1 -1
  148. package/dist/types/routes/data-set.d.ts +1 -1
  149. package/dist/types/routes/data-sync-changes.d.ts +1 -1
  150. package/dist/types/routes/data-sync-mutations.d.ts +1 -1
  151. package/dist/types/routes/data-transaction.d.ts +2 -2
  152. package/dist/types/routes/data-update.d.ts +1 -1
  153. package/dist/types/routes/data.d.ts +1 -1
  154. package/dist/types/routes/meta-info.d.ts +1 -1
  155. package/dist/types/routes/meta-logs.d.ts +1 -1
  156. package/dist/types/routes/meta-ping.d.ts +1 -1
  157. package/dist/types/routes/meta-stats.d.ts +1 -1
  158. package/dist/types/routes/oauth2-init.d.ts +1 -1
  159. package/dist/types/routes/oauth2-refresh.d.ts +1 -1
  160. package/dist/types/routes/oauth2-signin.d.ts +1 -1
  161. package/dist/types/routes/webmanager.d.ts +1 -1
  162. package/dist/types/schema/user.d.ts +2 -2
  163. package/dist/types/server.d.ts +3 -0
  164. package/dist/types/settings/index.d.ts +23 -0
  165. package/dist/types/shared/clients.d.ts +3 -3
  166. package/dist/types/shared/env.d.ts +2 -1
  167. package/dist/types/shared/http.d.ts +5 -0
  168. package/dist/types/shared/signin.d.ts +4 -4
  169. package/dist/types/shared/validate.d.ts +1 -1
  170. package/dist/types/websocket/index.d.ts +1 -1
  171. package/dist/types/websocket/manager.d.ts +1 -1
  172. package/img/acebase-swagger-ui.png +0 -0
  173. package/img/acebase-webmanager.png +0 -0
  174. package/package.json +9 -4
  175. package/src/routes/auth-signin.yaml +2 -2
  176. package/webmanager/acebase-client-browser.min.js +8 -11
  177. package/webmanager/index.html +1 -0
  178. package/webmanager/index.js +67 -71
  179. package/.vscode/launch.json +0 -24
  180. package/create-package-files +0 -25
  181. package/dist/cjs/auth.js.map +0 -1
  182. package/dist/cjs/cluster.js.map +0 -1
  183. package/dist/cjs/index.js.map +0 -1
  184. package/dist/cjs/logger.js.map +0 -1
  185. package/dist/cjs/middleware/404.js.map +0 -1
  186. package/dist/cjs/middleware/admin-only.js.map +0 -1
  187. package/dist/cjs/middleware/cache.js.map +0 -1
  188. package/dist/cjs/middleware/connection.js.map +0 -1
  189. package/dist/cjs/middleware/context.js.map +0 -1
  190. package/dist/cjs/middleware/cors.js.map +0 -1
  191. package/dist/cjs/middleware/swagger.js.map +0 -1
  192. package/dist/cjs/middleware/user.js.map +0 -1
  193. package/dist/cjs/oauth-providers/dropbox.js.map +0 -1
  194. package/dist/cjs/oauth-providers/facebook.js.map +0 -1
  195. package/dist/cjs/oauth-providers/google.js.map +0 -1
  196. package/dist/cjs/oauth-providers/index.js.map +0 -1
  197. package/dist/cjs/oauth-providers/instagram.js.map +0 -1
  198. package/dist/cjs/oauth-providers/oauth-provider.js.map +0 -1
  199. package/dist/cjs/oauth-providers/spotify.js.map +0 -1
  200. package/dist/cjs/routes/auth-change-password.js.map +0 -1
  201. package/dist/cjs/routes/auth-delete.js.map +0 -1
  202. package/dist/cjs/routes/auth-forgot-password.js.map +0 -1
  203. package/dist/cjs/routes/auth-reset-password.js.map +0 -1
  204. package/dist/cjs/routes/auth-signin.js.map +0 -1
  205. package/dist/cjs/routes/auth-signout.js.map +0 -1
  206. package/dist/cjs/routes/auth-signup.js.map +0 -1
  207. package/dist/cjs/routes/auth-state.js.map +0 -1
  208. package/dist/cjs/routes/auth-update.js.map +0 -1
  209. package/dist/cjs/routes/auth-verify-email.js.map +0 -1
  210. package/dist/cjs/routes/auth.js.map +0 -1
  211. package/dist/cjs/routes/data-exists.js.map +0 -1
  212. package/dist/cjs/routes/data-export.js.map +0 -1
  213. package/dist/cjs/routes/data-get.js.map +0 -1
  214. package/dist/cjs/routes/data-import.js.map +0 -1
  215. package/dist/cjs/routes/data-index-create.js.map +0 -1
  216. package/dist/cjs/routes/data-index-delete.js.map +0 -1
  217. package/dist/cjs/routes/data-index-list.js.map +0 -1
  218. package/dist/cjs/routes/data-query.js.map +0 -1
  219. package/dist/cjs/routes/data-reflect.js.map +0 -1
  220. package/dist/cjs/routes/data-schema-get.js.map +0 -1
  221. package/dist/cjs/routes/data-schema-set.js.map +0 -1
  222. package/dist/cjs/routes/data-schema-test.js.map +0 -1
  223. package/dist/cjs/routes/data-schemas-list.js.map +0 -1
  224. package/dist/cjs/routes/data-set.js.map +0 -1
  225. package/dist/cjs/routes/data-sync-changes.js.map +0 -1
  226. package/dist/cjs/routes/data-sync-mutations.js.map +0 -1
  227. package/dist/cjs/routes/data-transaction.js.map +0 -1
  228. package/dist/cjs/routes/data-update.js.map +0 -1
  229. package/dist/cjs/routes/data.js.map +0 -1
  230. package/dist/cjs/routes/docs.js.map +0 -1
  231. package/dist/cjs/routes/meta-info.js.map +0 -1
  232. package/dist/cjs/routes/meta-logs.js.map +0 -1
  233. package/dist/cjs/routes/meta-ping.js.map +0 -1
  234. package/dist/cjs/routes/meta-stats.js.map +0 -1
  235. package/dist/cjs/routes/meta.js.map +0 -1
  236. package/dist/cjs/routes/oauth2-init.js.map +0 -1
  237. package/dist/cjs/routes/oauth2-refresh.js.map +0 -1
  238. package/dist/cjs/routes/oauth2-signin.js.map +0 -1
  239. package/dist/cjs/routes/webmanager.js.map +0 -1
  240. package/dist/cjs/rules.js.map +0 -1
  241. package/dist/cjs/schema/user.js.map +0 -1
  242. package/dist/cjs/server.js.map +0 -1
  243. package/dist/cjs/settings/email.js.map +0 -1
  244. package/dist/cjs/settings/index.js.map +0 -1
  245. package/dist/cjs/shared/clients.js.map +0 -1
  246. package/dist/cjs/shared/email.js.map +0 -1
  247. package/dist/cjs/shared/env.js.map +0 -1
  248. package/dist/cjs/shared/error.js.map +0 -1
  249. package/dist/cjs/shared/http.js.map +0 -1
  250. package/dist/cjs/shared/password.js.map +0 -1
  251. package/dist/cjs/shared/rootpath.js.map +0 -1
  252. package/dist/cjs/shared/signin.js.map +0 -1
  253. package/dist/cjs/shared/simple-fetch.js.map +0 -1
  254. package/dist/cjs/shared/tokens.js.map +0 -1
  255. package/dist/cjs/shared/validate.js.map +0 -1
  256. package/dist/cjs/start.js.map +0 -1
  257. package/dist/cjs/test.js.map +0 -1
  258. package/dist/cjs/websocket/index.js.map +0 -1
  259. package/dist/cjs/websocket/manager.js.map +0 -1
  260. package/dist/cjs/websocket/socket.io.js.map +0 -1
  261. package/dist/esm/auth.js.map +0 -1
  262. package/dist/esm/cluster.js.map +0 -1
  263. package/dist/esm/index.js.map +0 -1
  264. package/dist/esm/logger.js.map +0 -1
  265. package/dist/esm/middleware/404.js.map +0 -1
  266. package/dist/esm/middleware/admin-only.js.map +0 -1
  267. package/dist/esm/middleware/cache.js.map +0 -1
  268. package/dist/esm/middleware/connection.js.map +0 -1
  269. package/dist/esm/middleware/context.js.map +0 -1
  270. package/dist/esm/middleware/cors.js.map +0 -1
  271. package/dist/esm/middleware/swagger.js.map +0 -1
  272. package/dist/esm/middleware/user.js.map +0 -1
  273. package/dist/esm/oauth-providers/dropbox.js.map +0 -1
  274. package/dist/esm/oauth-providers/facebook.js.map +0 -1
  275. package/dist/esm/oauth-providers/google.js.map +0 -1
  276. package/dist/esm/oauth-providers/index.js.map +0 -1
  277. package/dist/esm/oauth-providers/instagram.js.map +0 -1
  278. package/dist/esm/oauth-providers/oauth-provider.js.map +0 -1
  279. package/dist/esm/oauth-providers/spotify.js.map +0 -1
  280. package/dist/esm/routes/auth-change-password.js.map +0 -1
  281. package/dist/esm/routes/auth-delete.js.map +0 -1
  282. package/dist/esm/routes/auth-forgot-password.js.map +0 -1
  283. package/dist/esm/routes/auth-reset-password.js.map +0 -1
  284. package/dist/esm/routes/auth-signin.js.map +0 -1
  285. package/dist/esm/routes/auth-signout.js.map +0 -1
  286. package/dist/esm/routes/auth-signup.js.map +0 -1
  287. package/dist/esm/routes/auth-state.js.map +0 -1
  288. package/dist/esm/routes/auth-update.js.map +0 -1
  289. package/dist/esm/routes/auth-verify-email.js.map +0 -1
  290. package/dist/esm/routes/auth.js.map +0 -1
  291. package/dist/esm/routes/data-exists.js.map +0 -1
  292. package/dist/esm/routes/data-export.js.map +0 -1
  293. package/dist/esm/routes/data-get.js.map +0 -1
  294. package/dist/esm/routes/data-import.js.map +0 -1
  295. package/dist/esm/routes/data-index-create.js.map +0 -1
  296. package/dist/esm/routes/data-index-delete.js.map +0 -1
  297. package/dist/esm/routes/data-index-list.js.map +0 -1
  298. package/dist/esm/routes/data-query.js.map +0 -1
  299. package/dist/esm/routes/data-reflect.js.map +0 -1
  300. package/dist/esm/routes/data-schema-get.js.map +0 -1
  301. package/dist/esm/routes/data-schema-set.js.map +0 -1
  302. package/dist/esm/routes/data-schema-test.js.map +0 -1
  303. package/dist/esm/routes/data-schemas-list.js.map +0 -1
  304. package/dist/esm/routes/data-set.js.map +0 -1
  305. package/dist/esm/routes/data-sync-changes.js.map +0 -1
  306. package/dist/esm/routes/data-sync-mutations.js.map +0 -1
  307. package/dist/esm/routes/data-transaction.js.map +0 -1
  308. package/dist/esm/routes/data-update.js.map +0 -1
  309. package/dist/esm/routes/data.js.map +0 -1
  310. package/dist/esm/routes/docs.js.map +0 -1
  311. package/dist/esm/routes/meta-info.js.map +0 -1
  312. package/dist/esm/routes/meta-logs.js.map +0 -1
  313. package/dist/esm/routes/meta-ping.js.map +0 -1
  314. package/dist/esm/routes/meta-stats.js.map +0 -1
  315. package/dist/esm/routes/meta.js.map +0 -1
  316. package/dist/esm/routes/oauth2-init.js.map +0 -1
  317. package/dist/esm/routes/oauth2-refresh.js.map +0 -1
  318. package/dist/esm/routes/oauth2-signin.js.map +0 -1
  319. package/dist/esm/routes/webmanager.js.map +0 -1
  320. package/dist/esm/rules.js.map +0 -1
  321. package/dist/esm/schema/user.js.map +0 -1
  322. package/dist/esm/server.js.map +0 -1
  323. package/dist/esm/settings/email.js.map +0 -1
  324. package/dist/esm/settings/index.js.map +0 -1
  325. package/dist/esm/shared/clients.js.map +0 -1
  326. package/dist/esm/shared/email.js.map +0 -1
  327. package/dist/esm/shared/env.js.map +0 -1
  328. package/dist/esm/shared/error.js.map +0 -1
  329. package/dist/esm/shared/http.js.map +0 -1
  330. package/dist/esm/shared/password.js.map +0 -1
  331. package/dist/esm/shared/rootpath.js.map +0 -1
  332. package/dist/esm/shared/signin.js.map +0 -1
  333. package/dist/esm/shared/simple-fetch.js.map +0 -1
  334. package/dist/esm/shared/tokens.js.map +0 -1
  335. package/dist/esm/shared/validate.js.map +0 -1
  336. package/dist/esm/start.js.map +0 -1
  337. package/dist/esm/test.js.map +0 -1
  338. package/dist/esm/websocket/index.js.map +0 -1
  339. package/dist/esm/websocket/manager.js.map +0 -1
  340. package/dist/esm/websocket/socket.io.js.map +0 -1
  341. package/dist/types/auth.d.ts.map +0 -1
  342. package/dist/types/cluster.d.ts.map +0 -1
  343. package/dist/types/index.d.ts.map +0 -1
  344. package/dist/types/logger.d.ts.map +0 -1
  345. package/dist/types/middleware/404.d.ts.map +0 -1
  346. package/dist/types/middleware/admin-only.d.ts.map +0 -1
  347. package/dist/types/middleware/cache.d.ts.map +0 -1
  348. package/dist/types/middleware/connection.d.ts.map +0 -1
  349. package/dist/types/middleware/context.d.ts.map +0 -1
  350. package/dist/types/middleware/cors.d.ts.map +0 -1
  351. package/dist/types/middleware/swagger.d.ts.map +0 -1
  352. package/dist/types/middleware/user.d.ts.map +0 -1
  353. package/dist/types/oauth-providers/dropbox.d.ts.map +0 -1
  354. package/dist/types/oauth-providers/facebook.d.ts.map +0 -1
  355. package/dist/types/oauth-providers/google.d.ts.map +0 -1
  356. package/dist/types/oauth-providers/index.d.ts.map +0 -1
  357. package/dist/types/oauth-providers/instagram.d.ts.map +0 -1
  358. package/dist/types/oauth-providers/oauth-provider.d.ts.map +0 -1
  359. package/dist/types/oauth-providers/spotify.d.ts.map +0 -1
  360. package/dist/types/routes/auth-change-password.d.ts.map +0 -1
  361. package/dist/types/routes/auth-delete.d.ts.map +0 -1
  362. package/dist/types/routes/auth-forgot-password.d.ts.map +0 -1
  363. package/dist/types/routes/auth-reset-password.d.ts.map +0 -1
  364. package/dist/types/routes/auth-signin.d.ts.map +0 -1
  365. package/dist/types/routes/auth-signout.d.ts.map +0 -1
  366. package/dist/types/routes/auth-signup.d.ts.map +0 -1
  367. package/dist/types/routes/auth-state.d.ts.map +0 -1
  368. package/dist/types/routes/auth-update.d.ts.map +0 -1
  369. package/dist/types/routes/auth-verify-email.d.ts.map +0 -1
  370. package/dist/types/routes/auth.d.ts.map +0 -1
  371. package/dist/types/routes/data-exists.d.ts.map +0 -1
  372. package/dist/types/routes/data-export.d.ts.map +0 -1
  373. package/dist/types/routes/data-get.d.ts.map +0 -1
  374. package/dist/types/routes/data-import.d.ts.map +0 -1
  375. package/dist/types/routes/data-index-create.d.ts.map +0 -1
  376. package/dist/types/routes/data-index-delete.d.ts.map +0 -1
  377. package/dist/types/routes/data-index-list.d.ts.map +0 -1
  378. package/dist/types/routes/data-query.d.ts.map +0 -1
  379. package/dist/types/routes/data-reflect.d.ts.map +0 -1
  380. package/dist/types/routes/data-schema-get.d.ts.map +0 -1
  381. package/dist/types/routes/data-schema-set.d.ts.map +0 -1
  382. package/dist/types/routes/data-schema-test.d.ts.map +0 -1
  383. package/dist/types/routes/data-schemas-list.d.ts.map +0 -1
  384. package/dist/types/routes/data-set.d.ts.map +0 -1
  385. package/dist/types/routes/data-sync-changes.d.ts.map +0 -1
  386. package/dist/types/routes/data-sync-mutations.d.ts.map +0 -1
  387. package/dist/types/routes/data-transaction.d.ts.map +0 -1
  388. package/dist/types/routes/data-update.d.ts.map +0 -1
  389. package/dist/types/routes/data.d.ts.map +0 -1
  390. package/dist/types/routes/docs.d.ts.map +0 -1
  391. package/dist/types/routes/meta-info.d.ts.map +0 -1
  392. package/dist/types/routes/meta-logs.d.ts.map +0 -1
  393. package/dist/types/routes/meta-ping.d.ts.map +0 -1
  394. package/dist/types/routes/meta-stats.d.ts.map +0 -1
  395. package/dist/types/routes/meta.d.ts.map +0 -1
  396. package/dist/types/routes/oauth2-init.d.ts.map +0 -1
  397. package/dist/types/routes/oauth2-refresh.d.ts.map +0 -1
  398. package/dist/types/routes/oauth2-signin.d.ts.map +0 -1
  399. package/dist/types/routes/webmanager.d.ts.map +0 -1
  400. package/dist/types/rules.d.ts.map +0 -1
  401. package/dist/types/schema/user.d.ts.map +0 -1
  402. package/dist/types/server.d.ts.map +0 -1
  403. package/dist/types/settings/email.d.ts.map +0 -1
  404. package/dist/types/settings/index.d.ts.map +0 -1
  405. package/dist/types/shared/clients.d.ts.map +0 -1
  406. package/dist/types/shared/email.d.ts.map +0 -1
  407. package/dist/types/shared/env.d.ts.map +0 -1
  408. package/dist/types/shared/error.d.ts.map +0 -1
  409. package/dist/types/shared/http.d.ts.map +0 -1
  410. package/dist/types/shared/password.d.ts.map +0 -1
  411. package/dist/types/shared/rootpath.d.ts.map +0 -1
  412. package/dist/types/shared/signin.d.ts.map +0 -1
  413. package/dist/types/shared/simple-fetch.d.ts.map +0 -1
  414. package/dist/types/shared/tokens.d.ts.map +0 -1
  415. package/dist/types/shared/validate.d.ts.map +0 -1
  416. package/dist/types/start.d.ts.map +0 -1
  417. package/dist/types/test.d.ts.map +0 -1
  418. package/dist/types/websocket/index.d.ts.map +0 -1
  419. package/dist/types/websocket/manager.d.ts.map +0 -1
  420. package/dist/types/websocket/socket.io.d.ts.map +0 -1
  421. package/src/auth.ts +0 -87
  422. package/src/cluster.ts +0 -62
  423. package/src/index.ts +0 -4
  424. package/src/logger.ts +0 -56
  425. package/src/middleware/404.ts +0 -13
  426. package/src/middleware/admin-only.ts +0 -29
  427. package/src/middleware/cache.ts +0 -15
  428. package/src/middleware/connection.ts +0 -48
  429. package/src/middleware/context.ts +0 -23
  430. package/src/middleware/cors.ts +0 -49
  431. package/src/middleware/swagger.ts +0 -19
  432. package/src/middleware/user.ts +0 -51
  433. package/src/oauth-providers/dropbox.ts +0 -144
  434. package/src/oauth-providers/facebook.ts +0 -103
  435. package/src/oauth-providers/google.ts +0 -147
  436. package/src/oauth-providers/index.ts +0 -21
  437. package/src/oauth-providers/instagram.ts +0 -98
  438. package/src/oauth-providers/oauth-provider.ts +0 -65
  439. package/src/oauth-providers/spotify.ts +0 -127
  440. package/src/placeholder.d.ts +0 -12
  441. package/src/routes/auth-change-password.ts +0 -92
  442. package/src/routes/auth-delete.ts +0 -49
  443. package/src/routes/auth-forgot-password.ts +0 -77
  444. package/src/routes/auth-reset-password.ts +0 -96
  445. package/src/routes/auth-signin.ts +0 -55
  446. package/src/routes/auth-signout.ts +0 -64
  447. package/src/routes/auth-signup.ts +0 -164
  448. package/src/routes/auth-state.ts +0 -20
  449. package/src/routes/auth-update.ts +0 -149
  450. package/src/routes/auth-verify-email.ts +0 -75
  451. package/src/routes/auth.ts +0 -67
  452. package/src/routes/data-exists.ts +0 -31
  453. package/src/routes/data-export.ts +0 -51
  454. package/src/routes/data-get.ts +0 -67
  455. package/src/routes/data-import.ts +0 -56
  456. package/src/routes/data-index-create.ts +0 -82
  457. package/src/routes/data-index-delete.ts +0 -36
  458. package/src/routes/data-index-list.ts +0 -39
  459. package/src/routes/data-query.ts +0 -97
  460. package/src/routes/data-reflect.ts +0 -91
  461. package/src/routes/data-schema-get.ts +0 -36
  462. package/src/routes/data-schema-set.ts +0 -35
  463. package/src/routes/data-schema-test.ts +0 -48
  464. package/src/routes/data-schemas-list.ts +0 -31
  465. package/src/routes/data-set.ts +0 -83
  466. package/src/routes/data-sync-changes.ts +0 -77
  467. package/src/routes/data-sync-mutations.ts +0 -77
  468. package/src/routes/data-transaction.ts +0 -166
  469. package/src/routes/data-update.ts +0 -84
  470. package/src/routes/data.ts +0 -79
  471. package/src/routes/docs.ts +0 -249
  472. package/src/routes/meta-info.ts +0 -80
  473. package/src/routes/meta-logs.ts +0 -57
  474. package/src/routes/meta-ping.ts +0 -15
  475. package/src/routes/meta-stats.ts +0 -31
  476. package/src/routes/meta.ts +0 -22
  477. package/src/routes/oauth2-init.ts +0 -44
  478. package/src/routes/oauth2-refresh.ts +0 -39
  479. package/src/routes/oauth2-signin.ts +0 -286
  480. package/src/routes/webmanager.ts +0 -29
  481. package/src/rules.ts +0 -189
  482. package/src/schema/user.ts +0 -99
  483. package/src/server.ts +0 -419
  484. package/src/settings/email.ts +0 -18
  485. package/src/settings/index.ts +0 -241
  486. package/src/shared/clients.ts +0 -31
  487. package/src/shared/email.ts +0 -33
  488. package/src/shared/env.ts +0 -38
  489. package/src/shared/error.ts +0 -37
  490. package/src/shared/http.ts +0 -26
  491. package/src/shared/password.ts +0 -41
  492. package/src/shared/rootpath.ts +0 -17
  493. package/src/shared/signin.ts +0 -149
  494. package/src/shared/simple-fetch.ts +0 -65
  495. package/src/shared/tokens.ts +0 -77
  496. package/src/shared/validate.ts +0 -53
  497. package/src/start.ts +0 -48
  498. package/src/test.ts +0 -10
  499. package/src/websocket/index.ts +0 -336
  500. package/src/websocket/manager.ts +0 -46
  501. package/src/websocket/socket.io.ts +0 -90
  502. package/tsconfig-cjs.json +0 -11
  503. package/tsconfig.json +0 -22
@@ -1,83 +0,0 @@
1
- import { SchemaValidationError } from 'acebase';
2
- import { Transport } from 'acebase-core';
3
- import { RuleValidationFailCode } from '../rules';
4
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
5
- import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
6
-
7
- export class SetDataError extends Error {
8
- constructor(public code: 'invalid_serialized_value', message: string) {
9
- super(message);
10
- }
11
- }
12
- export type RequestQuery = null;
13
- export type RequestBody = Transport.SerializedValue; // { val: any; map?: string|Record<string, 'date'|'binary'|'reference'|'regexp'|'array'> };
14
- export type ResponseBody = { success: true } // 200
15
- | { code: 'invalid_serialized_value', message: string } // 400
16
- | { code: RuleValidationFailCode, message: string } // 403
17
- | { code: 'schema_validation_failed', message: string } // 422
18
- | { code: string, message: string } // 500
19
-
20
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
21
-
22
- export const addRoute = (env: RouteInitEnvironment) => {
23
-
24
- env.app.put(`/data/${env.db.name}/*`, async (req: Request, res) => {
25
-
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: req.user?.uid ?? null, path };
29
-
30
- const access = env.rules.userHasAccess(req.user, path, true);
31
- if (!access.allow) {
32
- env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null, rule_error: access.details?.message ?? null });
33
- return sendUnauthorizedError(res, access.code, access.message);
34
- }
35
-
36
- try {
37
- const data = req.body;
38
- if (typeof data?.val === 'undefined' || !['string','object','undefined'].includes(typeof data?.map)) {
39
- throw new SetDataError('invalid_serialized_value', 'The sent value is not properly serialized');
40
- }
41
- const val = Transport.deserialize(data);
42
-
43
- if (path === '' && req.user?.uid !== 'admin' && val !== null && typeof val === 'object') {
44
- // Non-admin user: remove any private properties from the update object
45
- Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
46
- }
47
-
48
- // Schema validation moved to storage, no need to check here but an early check won't do no harm!
49
- const validation = await env.db.schema.check(path, val, false);
50
- if (!validation.ok) {
51
- throw new SchemaValidationError(validation.reason);
52
- }
53
-
54
- await env.db.ref(path)
55
- .context(req.context)
56
- .set(val);
57
-
58
- // NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
59
- const returnContext = { acebase_cursor: req.context.acebase_cursor };
60
- res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
61
-
62
- res.send({ success: true });
63
- }
64
- catch (err) {
65
- if (err instanceof SchemaValidationError) {
66
- env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
67
- res.status(422).send({ code: 'schema_validation_failed', message: err.message });
68
- }
69
- else if (err instanceof SetDataError) {
70
- env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
71
- sendBadRequestError(res, err);
72
- }
73
- else {
74
- env.debug.error(`failed to set "${path}":`, err);
75
- env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
76
- sendError(res, err);
77
- }
78
- }
79
- });
80
-
81
- };
82
-
83
- export default addRoute;
@@ -1,77 +0,0 @@
1
- import { PathInfo, Transport, ValueChange } from 'acebase-core';
2
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
3
- import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
4
-
5
- export type RequestQuery = {
6
- path?: string;
7
- for?: Array<{ path: string, events: string[] }>;
8
- cursor?: string;
9
- timestamp?: string;
10
- };
11
- export type RequestBody = null;
12
- export type ResponseBody = ValueChange[] // 200
13
- | { code: 'no_transaction_logging', message: string } // 400
14
- | { code: 'invalid_request', message: string } // 400
15
- | { code: 'not_authorized', message: string } // 403
16
- | { code: 'unexpected', message: string }; // 500
17
-
18
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
19
-
20
- export const addRoute = (env: RouteInitEnvironment) => {
21
-
22
- env.app.get(`/sync/changes/${env.db.name}`, async (req: Request, res) => {
23
- // Gets effective changes for specific path(s) and event combinations since given cursor
24
- if (!env.config.transactions?.log) {
25
- return sendBadRequestError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
26
- }
27
- try {
28
- const data = req.query;
29
- let targets = typeof data.path === 'string'
30
- ? [{ path: data.path, events: ['value'] }]
31
- : typeof data.for === 'string'
32
- ? JSON.parse(data.for)
33
- : null;
34
- if (targets === null) {
35
- return sendBadRequestError(res, { code: 'invalid_request', message: 'Invalid changes request' });
36
- }
37
- if (targets.length === 0) {
38
- targets.push({ path: '', events: ['value'] });
39
- }
40
- // Filter out any requested paths user does not have access to.
41
- targets = targets.filter(target => {
42
- let path = target.path;
43
- if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
44
- // Only child_ events, check if they have access to children instead
45
- path = PathInfo.get(path).childPath('*');
46
- }
47
- return env.rules.userHasAccess(req.user, path, false).allow;
48
- });
49
- if (targets.length === 0) {
50
- return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
51
- }
52
-
53
- const { cursor } = data;
54
- let timestamp: number;
55
- if (typeof data.timestamp !== 'undefined') {
56
- timestamp = parseInt(data.timestamp);
57
- if (isNaN(timestamp)) {
58
- return sendBadRequestError(res, { code: 'wrong_timestamp', message: 'Timestamp is not a number' });
59
- }
60
- }
61
- const result = await env.db.api.getChanges({ for: targets, cursor, timestamp });
62
-
63
- res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
64
- res.contentType('application/json');
65
-
66
- const serialized = Transport.serialize2(result.changes);
67
- res.send(serialized as ValueChange[]);
68
- }
69
- catch(err) {
70
- sendError(res, err);
71
- }
72
- });
73
-
74
-
75
- };
76
-
77
- export default addRoute;
@@ -1,77 +0,0 @@
1
- import { PathInfo, Transport, ValueMutation } from 'acebase-core';
2
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
3
- import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
4
-
5
- export type RequestQuery = {
6
- path?: string;
7
- for?: Array<{ path: string, events: string[] }>;
8
- cursor?: string;
9
- timestamp?: string;
10
- };
11
- export type RequestBody = null;
12
- export type ResponseBody = ValueMutation[] // 200
13
- | { code: 'no_transaction_logging', message: string } // 400
14
- | { code: 'invalid_request', message: string } // 400
15
- | { code: 'not_authorized', message: string } // 403
16
- | { code: 'unexpected', message: string }; // 500
17
-
18
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
19
-
20
- export const addRoute = (env: RouteInitEnvironment) => {
21
-
22
- env.app.get(`/sync/mutations/${env.db.name}`, async (req: Request, res) => {
23
- // Gets mutations for specific path(s) and event combinations since given cursor
24
- if (!env.config.transactions?.log) {
25
- return sendBadRequestError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
26
- }
27
- try {
28
- const data = req.query;
29
- let targets = typeof data.path === 'string'
30
- ? [{ path: data.path, events: ['value'] }]
31
- : typeof data.for === 'string'
32
- ? JSON.parse(data.for)
33
- : null;
34
- if (targets === null) {
35
- return sendBadRequestError(res, { code: 'invalid_request', message: 'Invalid mutations request' });
36
- }
37
- if (targets.length === 0) {
38
- targets.push({ path: '', events: ['value'] });
39
- }
40
- // Filter out any requested paths user does not have access to.
41
- targets = targets.filter(target => {
42
- let path = target.path;
43
- if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
44
- // Only child_ events, check if they have access to children instead
45
- path = PathInfo.get(path).childPath('*');
46
- }
47
- return env.rules.userHasAccess(req.user, path, false).allow;
48
- });
49
- if (targets.length === 0) {
50
- return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
51
- }
52
-
53
- const { cursor } = data;
54
- let timestamp: number;
55
- if (typeof data.timestamp !== 'undefined') {
56
- timestamp = parseInt(data.timestamp);
57
- if (isNaN(timestamp)) {
58
- return sendBadRequestError(res, { code: 'wrong_timestamp', message: 'Timestamp is not a number' });
59
- }
60
- }
61
- const result = await env.db.api.getMutations({ for: targets, cursor, timestamp });
62
-
63
- res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
64
- res.contentType('application/json');
65
-
66
- const serialized = Transport.serialize2(result.mutations);
67
- res.send(serialized as ValueMutation[]);
68
- }
69
- catch(err) {
70
- sendError(res, err);
71
- }
72
- });
73
-
74
-
75
- };
76
-
77
- export default addRoute;
@@ -1,166 +0,0 @@
1
- import { SchemaValidationError } from 'acebase';
2
- import { ID, Transport, Api } from 'acebase-core';
3
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
4
- import { sendBadRequestError, sendError, sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
5
-
6
- export const TRANSACTION_TIMEOUT_MS = 10000; // 10s to finish a started transaction
7
-
8
- export class DataTransactionError extends Error {
9
- constructor(public code: 'invalid_serialized_value', message: string) {
10
- super(message);
11
- }
12
- }
13
-
14
- export type ApiTransactionDetails = {
15
- id: string;
16
- value: Transport.SerializedValue;
17
- };
18
- export type StartRequestQuery = null;
19
- export type StartRequestBody = {
20
- path: string;
21
- };
22
- export type StartResponseBody = ApiTransactionDetails // 200
23
- | { code: string, message: string } // 403
24
- | { code: 'unexpected', message: string }; // 500
25
- export type StartRequest = RouteRequest<any, StartResponseBody, StartRequestBody, StartRequestQuery>;
26
-
27
- export type FinishRequestQuery = null;
28
- export type FinishRequestBody = ApiTransactionDetails & { path: string };
29
- export type FinishResponseBody = 'done' // 200
30
- | { code: string, message: string } // 400, 403
31
- | 'transaction not found' // 410
32
- | string // 500
33
-
34
- export type FinishRequest = RouteRequest<any, FinishResponseBody, FinishRequestBody, FinishRequestQuery>;
35
-
36
- type Transaction = { id: string; started: number; path: string; context: any; finish?: (val?: any) => ReturnType<Api['transaction']>; timeout: NodeJS.Timeout };
37
-
38
- export const addRoutes = (env: RouteInitEnvironment) => {
39
-
40
- const _transactions = new Map<string, Transaction>();
41
-
42
- // Start transaction endpoint:
43
- env.app.post(`/transaction/${env.db.name}/start`, (req: StartRequest, res) => {
44
- const data = req.body;
45
-
46
- const LOG_ACTION = 'data.transaction.start';
47
- const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path: data.path };
48
-
49
- const access = env.rules.userHasAccess(req.user, data.path, true);
50
- if (!access.allow) {
51
- env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
52
- return sendUnauthorizedError(res, access.code, access.message);
53
- }
54
-
55
- // Start transaction
56
- const tx: Transaction = {
57
- id: ID.generate(),
58
- started: Date.now(),
59
- path: data.path,
60
- context: req.context,
61
- finish: undefined,
62
- timeout: setTimeout(() => {
63
- _transactions.delete(tx.id);
64
- tx.finish(); // Finish without value cancels the transaction
65
- }, TRANSACTION_TIMEOUT_MS)
66
- };
67
- _transactions.set(tx.id, tx);
68
-
69
- try {
70
- env.debug.verbose(`Transaction ${tx.id} starting...`);
71
-
72
- // const ref = db.ref(tx.path);
73
- const donePromise = env.db.api.transaction(tx.path, val => {
74
- env.debug.verbose(`Transaction ${tx.id} started with value: `, val);
75
- const currentValue = Transport.serialize(val);
76
- const promise = new Promise<any>((resolve) => {
77
- tx.finish = (val: any) => {
78
- env.debug.verbose(`Transaction ${tx.id} finishing with value: `, val);
79
- _transactions.delete(tx.id);
80
- resolve(val);
81
- return donePromise;
82
- };
83
- });
84
- res.send({ id: tx.id, value: currentValue });
85
- return promise;
86
- }, { context: tx.context });
87
- }
88
- catch (err) {
89
- env.debug.error(`failed to start transaction on "${tx.path}":`, err);
90
- env.log.error(LOG_ACTION, err.code ?? 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
91
- sendUnexpectedError(res, err);
92
- }
93
- });
94
-
95
- // Finish transaction endpoint:
96
- env.app.post(`/transaction/${env.db.name}/finish`, async (req: FinishRequest, res) => {
97
- const data = req.body;
98
- const LOG_ACTION = 'data.transaction.finish';
99
- const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path: data.path };
100
-
101
- const tx = _transactions.get(data.id);
102
- if (!tx || tx.path !== data.path) {
103
- env.log.error(LOG_ACTION, tx ? 'wrong_path' : 'not_found', { ...LOG_DETAILS, id: data.id, tx_path: tx?.path ?? null });
104
- res.statusCode = 410; // Gone
105
- res.send(`transaction not found`);
106
- return;
107
- }
108
- clearTimeout(tx.timeout);
109
- _transactions.delete(tx.id);
110
-
111
- const access = env.rules.userHasAccess(req.user, tx.path, true);
112
- if (!access.allow) {
113
- env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
114
- return sendUnauthorizedError(res, access.code, access.message);
115
- }
116
-
117
- // Finish transaction
118
- try {
119
- let cancel = false;
120
- if (typeof data.value === 'object' && (data.value === null || Object.keys(data.value).length === 0)) {
121
- // Returning undefined from a transaction callback should cancel the transaction
122
- // acebase-client (Transport.serialize) serializes value undefined as { val: undefined, map: undefined }, which
123
- // then is sent to the server as an empty object: {}
124
- cancel = true;
125
- }
126
- else if (typeof data.value?.val === 'undefined' || !['string','object','undefined'].includes(typeof data.value?.map)) {
127
- throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
128
- }
129
- const newValue = cancel ? undefined : Transport.deserialize(data.value);
130
-
131
- if (tx.path === '' && req.user?.uid !== 'admin' && newValue !== null && typeof newValue === 'object') {
132
- // Non-admin user: remove any private properties from the update object
133
- Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
134
- }
135
-
136
-
137
- const result = await tx.finish(newValue);
138
-
139
- // NEW: capture cursor and return it in the response context header
140
- if (!tx.context) { tx.context = {}; }
141
- tx.context.acebase_cursor = result.cursor;
142
- res.setHeader('AceBase-Context', JSON.stringify(tx.context));
143
-
144
- res.send('done');
145
- }
146
- catch (err) {
147
- tx.finish(); // Finish without value cancels the transaction
148
- if (err instanceof SchemaValidationError) {
149
- env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
150
- res.status(422).send({ code: 'schema_validation_failed', message: err.message });
151
- }
152
- else if (err instanceof DataTransactionError) {
153
- env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
154
- sendBadRequestError(res, err);
155
- }
156
- else {
157
- env.debug.error(`failed to finish transaction on "${tx.path}":`, err);
158
- env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
159
- sendError(res, err);
160
- }
161
- }
162
- });
163
-
164
- };
165
-
166
- export default addRoutes;
@@ -1,84 +0,0 @@
1
- import { SchemaValidationError } from 'acebase';
2
- import { Transport } from 'acebase-core';
3
- import { RuleValidationFailCode } from '../rules';
4
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
5
- import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
6
-
7
- export class UpdateDataError extends Error {
8
- constructor(public code: 'invalid_serialized_value', message: string) {
9
- super(message);
10
- }
11
- }
12
-
13
- export type RequestQuery = null;
14
- export type RequestBody = Transport.SerializedValue; //{ val: any; map?: string|Record<string, 'date'|'binary'|'reference'|'regexp'|'array'> };
15
- export type ResponseBody = { success: true } // 200
16
- | { code: 'invalid_serialized_value', message: string } // 400
17
- | { code: RuleValidationFailCode, message: string } // 403
18
- | { code: 'schema_validation_failed', message: string } // 422
19
- | { code: string, message: string } // 500
20
-
21
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
22
-
23
- export const addRoute = (env: RouteInitEnvironment) => {
24
-
25
- env.app.post(`/data/${env.db.name}/*`, async (req: Request, res) => {
26
-
27
- const path = req.path.slice(env.db.name.length + 7);
28
- const LOG_ACTION = 'data.update';
29
- const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path };
30
-
31
- const access = env.rules.userHasAccess(req.user, path, true);
32
- if (!access.allow) {
33
- env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null, rule_error: access.details?.message ?? null });
34
- return sendUnauthorizedError(res, access.code, access.message);
35
- }
36
-
37
- try {
38
- const data = req.body;
39
- if (typeof data?.val === 'undefined' || !['string','object','undefined'].includes(typeof data?.map)) {
40
- throw new UpdateDataError('invalid_serialized_value', 'The sent value is not properly serialized');
41
- }
42
- const val = Transport.deserialize(data);
43
-
44
- if (path === '' && req.user?.uid !== 'admin' && val !== null && typeof val === 'object') {
45
- // Non-admin user: remove any private properties from the update object
46
- Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
47
- }
48
-
49
- // Schema validation moved to storage, no need to check here but an early check won't do no harm!
50
- const validation = await env.db.schema.check(path, val, true);
51
- if (!validation.ok) {
52
- throw new SchemaValidationError(validation.reason);
53
- }
54
-
55
- await env.db.ref(path)
56
- .context(req.context)
57
- .update(val);
58
-
59
- // NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
60
- const returnContext = { acebase_cursor: req.context.acebase_cursor };
61
- res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
62
-
63
- res.send({ success: true });
64
- }
65
- catch(err) {
66
- if (err instanceof SchemaValidationError) {
67
- env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
68
- res.status(422).send({ code: 'schema_validation_failed', message: err.message });
69
- }
70
- else if (err instanceof UpdateDataError) {
71
- env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
72
- sendBadRequestError(res, err);
73
- }
74
- else {
75
- env.debug.error(`failed to update "${path}":`, err);
76
- env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
77
- sendError(res, err);
78
- }
79
- }
80
- });
81
-
82
- };
83
-
84
- export default addRoute;
@@ -1,79 +0,0 @@
1
- import { RouteInitEnvironment } from "../shared/env";
2
- import addContextMiddleware from "../middleware/context";
3
- import addGetDataRoute from './data-get';
4
- import addUpdateDataRoute from './data-update';
5
- import addSetDataRoute from './data-set';
6
- import addTransactionRoutes from './data-transaction';
7
- import addExistsRoute from './data-exists';
8
- import addReflectRoute from './data-reflect';
9
- import addImportDataRoute from './data-import';
10
- import addExportDataRoute from './data-export';
11
- import addQueryRoute from './data-query';
12
-
13
- // Indexes:
14
- import addListIndexesRoute from './data-index-list';
15
- import addCreateIndexRoute from './data-index-create';
16
- import addDeleteIndexRoute from './data-index-delete';
17
-
18
- // Schemas:
19
- import addListSchemasRoute from './data-schemas-list';
20
- import addGetSchemaRoute from './data-schema-get';
21
- import addSetSchemaRoute from './data-schema-set';
22
- import addTestSchemaRoute from './data-schema-test';
23
-
24
- // Sycnronization:
25
- import addSyncMutationsRoute from './data-sync-mutations';
26
- import addSyncChangesRoute from './data-sync-changes';
27
-
28
- export const addRoutes = (env: RouteInitEnvironment) => {
29
-
30
- // Add context middleware that handles AceBase-Context header
31
- addContextMiddleware(env);
32
-
33
- // Add get data endpoint
34
- addGetDataRoute(env);
35
-
36
- // Add update data endpoint
37
- addUpdateDataRoute(env);
38
-
39
- // Add set data endpoint
40
- addSetDataRoute(env);
41
-
42
- // add transaction routes (start & finish)
43
- addTransactionRoutes(env);
44
-
45
- // Add exists endpoint
46
- addExistsRoute(env);
47
-
48
- // Add reflect endpoint
49
- addReflectRoute(env);
50
-
51
- // Add import endpoint
52
- addImportDataRoute(env);
53
-
54
- // Add export endpoint
55
- addExportDataRoute(env);
56
-
57
- // Add query endpoint
58
- addQueryRoute(env);
59
-
60
- // Add index endpoints:
61
- addListIndexesRoute(env); // list indexes
62
- addCreateIndexRoute(env); // create index
63
- addDeleteIndexRoute(env); // delete index
64
-
65
- // Add schema endpoints:
66
- addListSchemasRoute(env); // list all
67
- addGetSchemaRoute(env); // get schema
68
- addSetSchemaRoute(env); // set schema
69
- addTestSchemaRoute(env); // test
70
-
71
- // Add sync mutations endpoint
72
- addSyncMutationsRoute(env);
73
-
74
- // add sync changes endpoint
75
- addSyncChangesRoute(env);
76
-
77
- };
78
-
79
- export default addRoutes;