acebase-server 1.13.3 → 1.14.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 (450) hide show
  1. package/create-package-files +25 -0
  2. package/dist/cjs/auth.js.map +1 -0
  3. package/dist/cjs/cluster.js.map +1 -0
  4. package/dist/cjs/index.d.ts +1 -1
  5. package/dist/cjs/index.js.map +1 -0
  6. package/dist/cjs/logger.js.map +1 -0
  7. package/dist/cjs/middleware/404.js.map +1 -0
  8. package/dist/cjs/middleware/admin-only.js.map +1 -0
  9. package/dist/cjs/middleware/cache.js.map +1 -0
  10. package/dist/cjs/middleware/connection.js.map +1 -0
  11. package/dist/cjs/middleware/context.js.map +1 -0
  12. package/dist/cjs/middleware/cors.js.map +1 -0
  13. package/dist/cjs/middleware/swagger.js.map +1 -0
  14. package/dist/cjs/middleware/user.js.map +1 -0
  15. package/dist/cjs/oauth-providers/dropbox.js.map +1 -0
  16. package/dist/cjs/oauth-providers/facebook.js.map +1 -0
  17. package/dist/cjs/oauth-providers/google.js.map +1 -0
  18. package/dist/cjs/oauth-providers/index.js.map +1 -0
  19. package/dist/cjs/oauth-providers/instagram.js.map +1 -0
  20. package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -0
  21. package/dist/cjs/oauth-providers/spotify.js.map +1 -0
  22. package/dist/cjs/routes/auth-change-password.js.map +1 -0
  23. package/dist/cjs/routes/auth-delete.js.map +1 -0
  24. package/dist/cjs/routes/auth-forgot-password.js.map +1 -0
  25. package/dist/cjs/routes/auth-reset-password.js.map +1 -0
  26. package/dist/cjs/routes/auth-signin.js.map +1 -0
  27. package/dist/cjs/routes/auth-signout.js.map +1 -0
  28. package/dist/cjs/routes/auth-signup.js.map +1 -0
  29. package/dist/cjs/routes/auth-state.js.map +1 -0
  30. package/dist/cjs/routes/auth-update.js.map +1 -0
  31. package/dist/cjs/routes/auth-verify-email.js.map +1 -0
  32. package/dist/cjs/routes/auth.js.map +1 -0
  33. package/dist/cjs/routes/data-exists.js.map +1 -0
  34. package/dist/cjs/routes/data-export.js.map +1 -0
  35. package/dist/cjs/routes/data-get.js.map +1 -0
  36. package/dist/cjs/routes/data-import.js.map +1 -0
  37. package/dist/cjs/routes/data-index-create.js.map +1 -0
  38. package/dist/cjs/routes/data-index-delete.js.map +1 -0
  39. package/dist/cjs/routes/data-index-list.js.map +1 -0
  40. package/dist/cjs/routes/data-query.js.map +1 -0
  41. package/dist/cjs/routes/data-reflect.js.map +1 -0
  42. package/dist/cjs/routes/data-schema-get.js.map +1 -0
  43. package/dist/cjs/routes/data-schema-set.js.map +1 -0
  44. package/dist/cjs/routes/data-schema-test.js.map +1 -0
  45. package/dist/cjs/routes/data-schemas-list.js.map +1 -0
  46. package/dist/cjs/routes/data-set.js.map +1 -0
  47. package/dist/cjs/routes/data-sync-changes.js.map +1 -0
  48. package/dist/cjs/routes/data-sync-mutations.js.map +1 -0
  49. package/dist/cjs/routes/data-transaction.js.map +1 -0
  50. package/dist/cjs/routes/data-update.js.map +1 -0
  51. package/dist/cjs/routes/data.js.map +1 -0
  52. package/dist/cjs/routes/docs.js.map +1 -0
  53. package/dist/cjs/routes/meta-info.js.map +1 -0
  54. package/dist/cjs/routes/meta-logs.js.map +1 -0
  55. package/dist/cjs/routes/meta-ping.js.map +1 -0
  56. package/dist/cjs/routes/meta-stats.js.map +1 -0
  57. package/dist/cjs/routes/meta.js.map +1 -0
  58. package/dist/cjs/routes/oauth2-init.js.map +1 -0
  59. package/dist/cjs/routes/oauth2-refresh.js.map +1 -0
  60. package/dist/cjs/routes/oauth2-signin.js.map +1 -0
  61. package/dist/cjs/routes/webmanager.js.map +1 -0
  62. package/dist/cjs/rules.js +2 -9
  63. package/dist/cjs/rules.js.map +1 -0
  64. package/dist/cjs/schema/user.js.map +1 -0
  65. package/dist/cjs/server.js +1 -1
  66. package/dist/cjs/server.js.map +1 -0
  67. package/dist/cjs/settings/email.js.map +1 -0
  68. package/dist/cjs/settings/index.js +1 -1
  69. package/dist/cjs/settings/index.js.map +1 -0
  70. package/dist/cjs/shared/clients.js.map +1 -0
  71. package/dist/cjs/shared/email.js.map +1 -0
  72. package/dist/cjs/shared/env.js.map +1 -0
  73. package/dist/cjs/shared/error.js.map +1 -0
  74. package/dist/cjs/shared/http.js.map +1 -0
  75. package/dist/cjs/shared/password.js.map +1 -0
  76. package/dist/cjs/shared/rootpath.js.map +1 -0
  77. package/dist/cjs/shared/signin.js.map +1 -0
  78. package/dist/cjs/shared/simple-fetch.js.map +1 -0
  79. package/dist/cjs/shared/tokens.js.map +1 -0
  80. package/dist/cjs/shared/validate.js.map +1 -0
  81. package/dist/cjs/start.js.map +1 -0
  82. package/dist/cjs/test.js.map +1 -0
  83. package/dist/cjs/websocket/index.js.map +1 -0
  84. package/dist/cjs/websocket/manager.js +1 -1
  85. package/dist/cjs/websocket/manager.js.map +1 -0
  86. package/dist/cjs/websocket/socket.io.js.map +1 -0
  87. package/dist/esm/auth.js.map +1 -0
  88. package/dist/esm/cluster.js.map +1 -0
  89. package/dist/esm/index.d.ts +1 -1
  90. package/dist/esm/index.js.map +1 -0
  91. package/dist/esm/logger.js.map +1 -0
  92. package/dist/esm/middleware/404.js.map +1 -0
  93. package/dist/esm/middleware/admin-only.js.map +1 -0
  94. package/dist/esm/middleware/cache.js.map +1 -0
  95. package/dist/esm/middleware/connection.js.map +1 -0
  96. package/dist/esm/middleware/context.js.map +1 -0
  97. package/dist/esm/middleware/cors.js.map +1 -0
  98. package/dist/esm/middleware/swagger.js.map +1 -0
  99. package/dist/esm/middleware/user.js.map +1 -0
  100. package/dist/esm/oauth-providers/dropbox.js.map +1 -0
  101. package/dist/esm/oauth-providers/facebook.js.map +1 -0
  102. package/dist/esm/oauth-providers/google.js.map +1 -0
  103. package/dist/esm/oauth-providers/index.js.map +1 -0
  104. package/dist/esm/oauth-providers/instagram.js.map +1 -0
  105. package/dist/esm/oauth-providers/oauth-provider.js.map +1 -0
  106. package/dist/esm/oauth-providers/spotify.js.map +1 -0
  107. package/dist/esm/routes/auth-change-password.js.map +1 -0
  108. package/dist/esm/routes/auth-delete.js.map +1 -0
  109. package/dist/esm/routes/auth-forgot-password.js.map +1 -0
  110. package/dist/esm/routes/auth-reset-password.js.map +1 -0
  111. package/dist/esm/routes/auth-signin.js.map +1 -0
  112. package/dist/esm/routes/auth-signout.js.map +1 -0
  113. package/dist/esm/routes/auth-signup.js.map +1 -0
  114. package/dist/esm/routes/auth-state.js.map +1 -0
  115. package/dist/esm/routes/auth-update.js.map +1 -0
  116. package/dist/esm/routes/auth-verify-email.js.map +1 -0
  117. package/dist/esm/routes/auth.js.map +1 -0
  118. package/dist/esm/routes/data-exists.js.map +1 -0
  119. package/dist/esm/routes/data-export.js.map +1 -0
  120. package/dist/esm/routes/data-get.js.map +1 -0
  121. package/dist/esm/routes/data-import.js.map +1 -0
  122. package/dist/esm/routes/data-index-create.js.map +1 -0
  123. package/dist/esm/routes/data-index-delete.js.map +1 -0
  124. package/dist/esm/routes/data-index-list.js.map +1 -0
  125. package/dist/esm/routes/data-query.js.map +1 -0
  126. package/dist/esm/routes/data-reflect.js.map +1 -0
  127. package/dist/esm/routes/data-schema-get.js.map +1 -0
  128. package/dist/esm/routes/data-schema-set.js.map +1 -0
  129. package/dist/esm/routes/data-schema-test.js.map +1 -0
  130. package/dist/esm/routes/data-schemas-list.js.map +1 -0
  131. package/dist/esm/routes/data-set.js.map +1 -0
  132. package/dist/esm/routes/data-sync-changes.js.map +1 -0
  133. package/dist/esm/routes/data-sync-mutations.js.map +1 -0
  134. package/dist/esm/routes/data-transaction.js.map +1 -0
  135. package/dist/esm/routes/data-update.js.map +1 -0
  136. package/dist/esm/routes/data.js.map +1 -0
  137. package/dist/esm/routes/docs.js.map +1 -0
  138. package/dist/esm/routes/meta-info.js.map +1 -0
  139. package/dist/esm/routes/meta-logs.js.map +1 -0
  140. package/dist/esm/routes/meta-ping.js.map +1 -0
  141. package/dist/esm/routes/meta-stats.js.map +1 -0
  142. package/dist/esm/routes/meta.js.map +1 -0
  143. package/dist/esm/routes/oauth2-init.js.map +1 -0
  144. package/dist/esm/routes/oauth2-refresh.js.map +1 -0
  145. package/dist/esm/routes/oauth2-signin.js.map +1 -0
  146. package/dist/esm/routes/webmanager.js.map +1 -0
  147. package/dist/esm/rules.js +2 -9
  148. package/dist/esm/rules.js.map +1 -0
  149. package/dist/esm/schema/user.js.map +1 -0
  150. package/dist/esm/server.js +1 -1
  151. package/dist/esm/server.js.map +1 -0
  152. package/dist/esm/settings/email.js.map +1 -0
  153. package/dist/esm/settings/index.js +1 -1
  154. package/dist/esm/settings/index.js.map +1 -0
  155. package/dist/esm/shared/clients.js.map +1 -0
  156. package/dist/esm/shared/email.js.map +1 -0
  157. package/dist/esm/shared/env.js.map +1 -0
  158. package/dist/esm/shared/error.js.map +1 -0
  159. package/dist/esm/shared/http.js.map +1 -0
  160. package/dist/esm/shared/password.js.map +1 -0
  161. package/dist/esm/shared/rootpath.js.map +1 -0
  162. package/dist/esm/shared/signin.js.map +1 -0
  163. package/dist/esm/shared/simple-fetch.js.map +1 -0
  164. package/dist/esm/shared/tokens.js.map +1 -0
  165. package/dist/esm/shared/validate.js.map +1 -0
  166. package/dist/esm/start.js.map +1 -0
  167. package/dist/esm/test.js.map +1 -0
  168. package/dist/esm/websocket/index.js.map +1 -0
  169. package/dist/esm/websocket/manager.js +1 -1
  170. package/dist/esm/websocket/manager.js.map +1 -0
  171. package/dist/esm/websocket/socket.io.js.map +1 -0
  172. package/dist/types/auth.d.ts +1 -0
  173. package/dist/types/auth.d.ts.map +1 -0
  174. package/dist/types/cluster.d.ts +1 -0
  175. package/dist/types/cluster.d.ts.map +1 -0
  176. package/dist/types/index.d.ts +1 -0
  177. package/dist/types/index.d.ts.map +1 -0
  178. package/dist/types/logger.d.ts +1 -0
  179. package/dist/types/logger.d.ts.map +1 -0
  180. package/dist/types/middleware/404.d.ts +1 -0
  181. package/dist/types/middleware/404.d.ts.map +1 -0
  182. package/dist/types/middleware/admin-only.d.ts +1 -0
  183. package/dist/types/middleware/admin-only.d.ts.map +1 -0
  184. package/dist/types/middleware/cache.d.ts +1 -0
  185. package/dist/types/middleware/cache.d.ts.map +1 -0
  186. package/dist/types/middleware/connection.d.ts +1 -0
  187. package/dist/types/middleware/connection.d.ts.map +1 -0
  188. package/dist/types/middleware/context.d.ts +1 -0
  189. package/dist/types/middleware/context.d.ts.map +1 -0
  190. package/dist/types/middleware/cors.d.ts +1 -0
  191. package/dist/types/middleware/cors.d.ts.map +1 -0
  192. package/dist/types/middleware/swagger.d.ts +1 -0
  193. package/dist/types/middleware/swagger.d.ts.map +1 -0
  194. package/dist/types/middleware/user.d.ts +1 -0
  195. package/dist/types/middleware/user.d.ts.map +1 -0
  196. package/dist/types/oauth-providers/dropbox.d.ts +1 -0
  197. package/dist/types/oauth-providers/dropbox.d.ts.map +1 -0
  198. package/dist/types/oauth-providers/facebook.d.ts +1 -0
  199. package/dist/types/oauth-providers/facebook.d.ts.map +1 -0
  200. package/dist/types/oauth-providers/google.d.ts +1 -0
  201. package/dist/types/oauth-providers/google.d.ts.map +1 -0
  202. package/dist/types/oauth-providers/index.d.ts +1 -0
  203. package/dist/types/oauth-providers/index.d.ts.map +1 -0
  204. package/dist/types/oauth-providers/instagram.d.ts +1 -0
  205. package/dist/types/oauth-providers/instagram.d.ts.map +1 -0
  206. package/dist/types/oauth-providers/oauth-provider.d.ts +1 -0
  207. package/dist/types/oauth-providers/oauth-provider.d.ts.map +1 -0
  208. package/dist/types/oauth-providers/spotify.d.ts +1 -0
  209. package/dist/types/oauth-providers/spotify.d.ts.map +1 -0
  210. package/dist/types/routes/auth-change-password.d.ts +1 -0
  211. package/dist/types/routes/auth-change-password.d.ts.map +1 -0
  212. package/dist/types/routes/auth-delete.d.ts +1 -0
  213. package/dist/types/routes/auth-delete.d.ts.map +1 -0
  214. package/dist/types/routes/auth-forgot-password.d.ts +1 -0
  215. package/dist/types/routes/auth-forgot-password.d.ts.map +1 -0
  216. package/dist/types/routes/auth-reset-password.d.ts +1 -0
  217. package/dist/types/routes/auth-reset-password.d.ts.map +1 -0
  218. package/dist/types/routes/auth-signin.d.ts +1 -0
  219. package/dist/types/routes/auth-signin.d.ts.map +1 -0
  220. package/dist/types/routes/auth-signout.d.ts +1 -0
  221. package/dist/types/routes/auth-signout.d.ts.map +1 -0
  222. package/dist/types/routes/auth-signup.d.ts +1 -0
  223. package/dist/types/routes/auth-signup.d.ts.map +1 -0
  224. package/dist/types/routes/auth-state.d.ts +1 -0
  225. package/dist/types/routes/auth-state.d.ts.map +1 -0
  226. package/dist/types/routes/auth-update.d.ts +1 -0
  227. package/dist/types/routes/auth-update.d.ts.map +1 -0
  228. package/dist/types/routes/auth-verify-email.d.ts +1 -0
  229. package/dist/types/routes/auth-verify-email.d.ts.map +1 -0
  230. package/dist/types/routes/auth.d.ts +1 -0
  231. package/dist/types/routes/auth.d.ts.map +1 -0
  232. package/dist/types/routes/data-exists.d.ts +1 -0
  233. package/dist/types/routes/data-exists.d.ts.map +1 -0
  234. package/dist/types/routes/data-export.d.ts +1 -0
  235. package/dist/types/routes/data-export.d.ts.map +1 -0
  236. package/dist/types/routes/data-get.d.ts +3 -2
  237. package/dist/types/routes/data-get.d.ts.map +1 -0
  238. package/dist/types/routes/data-import.d.ts +1 -0
  239. package/dist/types/routes/data-import.d.ts.map +1 -0
  240. package/dist/types/routes/data-index-create.d.ts +1 -0
  241. package/dist/types/routes/data-index-create.d.ts.map +1 -0
  242. package/dist/types/routes/data-index-delete.d.ts +1 -0
  243. package/dist/types/routes/data-index-delete.d.ts.map +1 -0
  244. package/dist/types/routes/data-index-list.d.ts +1 -0
  245. package/dist/types/routes/data-index-list.d.ts.map +1 -0
  246. package/dist/types/routes/data-query.d.ts +1 -0
  247. package/dist/types/routes/data-query.d.ts.map +1 -0
  248. package/dist/types/routes/data-reflect.d.ts +1 -0
  249. package/dist/types/routes/data-reflect.d.ts.map +1 -0
  250. package/dist/types/routes/data-schema-get.d.ts +1 -0
  251. package/dist/types/routes/data-schema-get.d.ts.map +1 -0
  252. package/dist/types/routes/data-schema-set.d.ts +2 -1
  253. package/dist/types/routes/data-schema-set.d.ts.map +1 -0
  254. package/dist/types/routes/data-schema-test.d.ts +3 -4
  255. package/dist/types/routes/data-schema-test.d.ts.map +1 -0
  256. package/dist/types/routes/data-schemas-list.d.ts +1 -0
  257. package/dist/types/routes/data-schemas-list.d.ts.map +1 -0
  258. package/dist/types/routes/data-set.d.ts +3 -2
  259. package/dist/types/routes/data-set.d.ts.map +1 -0
  260. package/dist/types/routes/data-sync-changes.d.ts +2 -1
  261. package/dist/types/routes/data-sync-changes.d.ts.map +1 -0
  262. package/dist/types/routes/data-sync-mutations.d.ts +2 -1
  263. package/dist/types/routes/data-sync-mutations.d.ts.map +1 -0
  264. package/dist/types/routes/data-transaction.d.ts +3 -2
  265. package/dist/types/routes/data-transaction.d.ts.map +1 -0
  266. package/dist/types/routes/data-update.d.ts +3 -2
  267. package/dist/types/routes/data-update.d.ts.map +1 -0
  268. package/dist/types/routes/data.d.ts +1 -0
  269. package/dist/types/routes/data.d.ts.map +1 -0
  270. package/dist/types/routes/docs.d.ts +1 -0
  271. package/dist/types/routes/docs.d.ts.map +1 -0
  272. package/dist/types/routes/meta-info.d.ts +1 -0
  273. package/dist/types/routes/meta-info.d.ts.map +1 -0
  274. package/dist/types/routes/meta-logs.d.ts +2 -1
  275. package/dist/types/routes/meta-logs.d.ts.map +1 -0
  276. package/dist/types/routes/meta-ping.d.ts +1 -0
  277. package/dist/types/routes/meta-ping.d.ts.map +1 -0
  278. package/dist/types/routes/meta-stats.d.ts +1 -0
  279. package/dist/types/routes/meta-stats.d.ts.map +1 -0
  280. package/dist/types/routes/meta.d.ts +1 -0
  281. package/dist/types/routes/meta.d.ts.map +1 -0
  282. package/dist/types/routes/oauth2-init.d.ts +1 -0
  283. package/dist/types/routes/oauth2-init.d.ts.map +1 -0
  284. package/dist/types/routes/oauth2-refresh.d.ts +1 -0
  285. package/dist/types/routes/oauth2-refresh.d.ts.map +1 -0
  286. package/dist/types/routes/oauth2-signin.d.ts +1 -0
  287. package/dist/types/routes/oauth2-signin.d.ts.map +1 -0
  288. package/dist/types/routes/webmanager.d.ts +1 -0
  289. package/dist/types/routes/webmanager.d.ts.map +1 -0
  290. package/dist/types/rules.d.ts +1 -7
  291. package/dist/types/rules.d.ts.map +1 -0
  292. package/dist/types/schema/user.d.ts +1 -0
  293. package/dist/types/schema/user.d.ts.map +1 -0
  294. package/dist/types/server.d.ts +1 -0
  295. package/dist/types/server.d.ts.map +1 -0
  296. package/dist/types/settings/email.d.ts +1 -0
  297. package/dist/types/settings/email.d.ts.map +1 -0
  298. package/dist/types/settings/index.d.ts +2 -1
  299. package/dist/types/settings/index.d.ts.map +1 -0
  300. package/dist/types/shared/clients.d.ts +4 -3
  301. package/dist/types/shared/clients.d.ts.map +1 -0
  302. package/dist/types/shared/email.d.ts +1 -0
  303. package/dist/types/shared/email.d.ts.map +1 -0
  304. package/dist/types/shared/env.d.ts +2 -2
  305. package/dist/types/shared/env.d.ts.map +1 -0
  306. package/dist/types/shared/error.d.ts +1 -0
  307. package/dist/types/shared/error.d.ts.map +1 -0
  308. package/dist/types/shared/http.d.ts +1 -0
  309. package/dist/types/shared/http.d.ts.map +1 -0
  310. package/dist/types/shared/password.d.ts +1 -0
  311. package/dist/types/shared/password.d.ts.map +1 -0
  312. package/dist/types/shared/rootpath.d.ts +1 -0
  313. package/dist/types/shared/rootpath.d.ts.map +1 -0
  314. package/dist/types/shared/signin.d.ts +1 -0
  315. package/dist/types/shared/signin.d.ts.map +1 -0
  316. package/dist/types/shared/simple-fetch.d.ts +1 -0
  317. package/dist/types/shared/simple-fetch.d.ts.map +1 -0
  318. package/dist/types/shared/tokens.d.ts +1 -0
  319. package/dist/types/shared/tokens.d.ts.map +1 -0
  320. package/dist/types/shared/validate.d.ts +1 -0
  321. package/dist/types/shared/validate.d.ts.map +1 -0
  322. package/dist/types/start.d.ts +1 -0
  323. package/dist/types/start.d.ts.map +1 -0
  324. package/dist/types/test.d.ts +1 -0
  325. package/dist/types/test.d.ts.map +1 -0
  326. package/dist/types/websocket/index.d.ts +1 -0
  327. package/dist/types/websocket/index.d.ts.map +1 -0
  328. package/dist/types/websocket/manager.d.ts +11 -10
  329. package/dist/types/websocket/manager.d.ts.map +1 -0
  330. package/dist/types/websocket/socket.io.d.ts +1 -0
  331. package/dist/types/websocket/socket.io.d.ts.map +1 -0
  332. package/package.json +3 -3
  333. package/src/auth.ts +87 -0
  334. package/src/cluster.ts +62 -0
  335. package/src/index.ts +4 -0
  336. package/src/logger.ts +56 -0
  337. package/src/middleware/404.ts +13 -0
  338. package/src/middleware/admin-only.ts +29 -0
  339. package/src/middleware/cache.ts +15 -0
  340. package/src/middleware/connection.ts +48 -0
  341. package/src/middleware/context.ts +23 -0
  342. package/src/middleware/cors.ts +49 -0
  343. package/src/middleware/swagger.ts +19 -0
  344. package/src/middleware/user.ts +51 -0
  345. package/src/oauth-providers/dropbox.ts +144 -0
  346. package/src/oauth-providers/facebook.ts +103 -0
  347. package/src/oauth-providers/google.ts +147 -0
  348. package/src/oauth-providers/index.ts +21 -0
  349. package/src/oauth-providers/instagram.ts +98 -0
  350. package/src/oauth-providers/oauth-provider.ts +65 -0
  351. package/src/oauth-providers/spotify.ts +127 -0
  352. package/src/placeholder.d.ts +12 -0
  353. package/src/routes/auth-change-password.ts +92 -0
  354. package/src/routes/auth-change-password.yaml +74 -0
  355. package/src/routes/auth-delete.ts +49 -0
  356. package/src/routes/auth-delete.yaml +78 -0
  357. package/src/routes/auth-forgot-password.ts +77 -0
  358. package/src/routes/auth-forgot-password.yaml +50 -0
  359. package/src/routes/auth-reset-password.ts +96 -0
  360. package/src/routes/auth-reset-password.yaml +54 -0
  361. package/src/routes/auth-signin.ts +55 -0
  362. package/src/routes/auth-signin.yaml +130 -0
  363. package/src/routes/auth-signout.ts +64 -0
  364. package/src/routes/auth-signout.yaml +46 -0
  365. package/src/routes/auth-signup.ts +164 -0
  366. package/src/routes/auth-signup.yaml +136 -0
  367. package/src/routes/auth-state.ts +20 -0
  368. package/src/routes/auth-state.yaml +29 -0
  369. package/src/routes/auth-update.ts +149 -0
  370. package/src/routes/auth-update.yaml +152 -0
  371. package/src/routes/auth-verify-email.ts +75 -0
  372. package/src/routes/auth-verify-email.yaml +53 -0
  373. package/src/routes/auth.ts +67 -0
  374. package/src/routes/data-exists.ts +31 -0
  375. package/src/routes/data-exists.yaml +44 -0
  376. package/src/routes/data-export.ts +51 -0
  377. package/src/routes/data-export.yaml +64 -0
  378. package/src/routes/data-get.ts +67 -0
  379. package/src/routes/data-get.yaml +54 -0
  380. package/src/routes/data-import.ts +56 -0
  381. package/src/routes/data-import.yaml +75 -0
  382. package/src/routes/data-index-create.ts +82 -0
  383. package/src/routes/data-index-create.yaml +105 -0
  384. package/src/routes/data-index-delete.ts +36 -0
  385. package/src/routes/data-index-delete.yaml +51 -0
  386. package/src/routes/data-index-list.ts +39 -0
  387. package/src/routes/data-index-list.yaml +84 -0
  388. package/src/routes/data-query.ts +97 -0
  389. package/src/routes/data-query.yaml +166 -0
  390. package/src/routes/data-reflect.ts +91 -0
  391. package/src/routes/data-reflect.yaml +124 -0
  392. package/src/routes/data-schema-get.ts +36 -0
  393. package/src/routes/data-schema-get.yaml +53 -0
  394. package/src/routes/data-schema-set.ts +35 -0
  395. package/src/routes/data-schema-set.yaml +60 -0
  396. package/src/routes/data-schema-test.ts +48 -0
  397. package/src/routes/data-schema-test.yaml +66 -0
  398. package/src/routes/data-schemas-list.ts +31 -0
  399. package/src/routes/data-schemas-list.yaml +41 -0
  400. package/src/routes/data-set.ts +83 -0
  401. package/src/routes/data-set.yaml +77 -0
  402. package/src/routes/data-sync-changes.ts +77 -0
  403. package/src/routes/data-sync-changes.yaml +67 -0
  404. package/src/routes/data-sync-mutations.ts +77 -0
  405. package/src/routes/data-sync-mutations.yaml +67 -0
  406. package/src/routes/data-transaction-finish.yaml +82 -0
  407. package/src/routes/data-transaction-start.yaml +58 -0
  408. package/src/routes/data-transaction.ts +166 -0
  409. package/src/routes/data-update.ts +84 -0
  410. package/src/routes/data-update.yaml +77 -0
  411. package/src/routes/data.ts +79 -0
  412. package/src/routes/docs.ts +249 -0
  413. package/src/routes/meta-info.ts +80 -0
  414. package/src/routes/meta-info.yaml +41 -0
  415. package/src/routes/meta-logs.ts +57 -0
  416. package/src/routes/meta-ping.ts +15 -0
  417. package/src/routes/meta-ping.yaml +23 -0
  418. package/src/routes/meta-stats.ts +31 -0
  419. package/src/routes/meta-stats.yaml +41 -0
  420. package/src/routes/meta.ts +22 -0
  421. package/src/routes/oauth2-init.ts +44 -0
  422. package/src/routes/oauth2-init.yaml +63 -0
  423. package/src/routes/oauth2-refresh.ts +39 -0
  424. package/src/routes/oauth2-refresh.yaml +65 -0
  425. package/src/routes/oauth2-signin.ts +286 -0
  426. package/src/routes/oauth2-signin.yaml +66 -0
  427. package/src/routes/webmanager.ts +29 -0
  428. package/src/rules.ts +189 -0
  429. package/src/schema/user.ts +99 -0
  430. package/src/server.ts +419 -0
  431. package/src/settings/email.ts +18 -0
  432. package/src/settings/index.ts +241 -0
  433. package/src/shared/clients.ts +31 -0
  434. package/src/shared/email.ts +33 -0
  435. package/src/shared/env.ts +38 -0
  436. package/src/shared/error.ts +37 -0
  437. package/src/shared/http.ts +26 -0
  438. package/src/shared/password.ts +41 -0
  439. package/src/shared/rootpath.ts +17 -0
  440. package/src/shared/signin.ts +149 -0
  441. package/src/shared/simple-fetch.ts +65 -0
  442. package/src/shared/tokens.ts +77 -0
  443. package/src/shared/validate.ts +53 -0
  444. package/src/start.ts +48 -0
  445. package/src/test.ts +10 -0
  446. package/src/websocket/index.ts +336 -0
  447. package/src/websocket/manager.ts +46 -0
  448. package/src/websocket/socket.io.ts +90 -0
  449. package/tsconfig-cjs.json +11 -0
  450. package/tsconfig.json +22 -0
@@ -0,0 +1,77 @@
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;
@@ -0,0 +1,67 @@
1
+ /sync/mutations/{dbname}:
2
+ get:
3
+ tags:
4
+ - data
5
+ summary: Gets mutations since cursor
6
+ description: Gets all mutations for specific path(s) and event combinations since given cursor. Use either the _path_ or _for_ parameter. If both are given, only _path_ is used.
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ - name: path
16
+ in: query
17
+ description: "single database path to get all changes for (equivalent to _for_ `[{ path, events: ['value'] }]`)"
18
+ schema:
19
+ type: string
20
+ example: collection
21
+ - name: for
22
+ in: query
23
+ description: JSON array of path / events combinations
24
+ schema:
25
+ type: string
26
+ example: "[{ path: 'collection', events: ['child_changed'] }]"
27
+ - name: cursor
28
+ in: query
29
+ description: previously acquired cursor to use
30
+ schema:
31
+ type: string
32
+ example: l2a37q55000008ll8dyngkny
33
+ - name: timestamp
34
+ in: query
35
+ description: instead of a cursor, you can also use a timestamp (ms since 1970/01/01)
36
+ schema:
37
+ type: integer
38
+ example: ""
39
+ responses:
40
+ 200:
41
+ description: Returns an array of all mutations to the requested selection
42
+ content:
43
+ 'application/json':
44
+ schema:
45
+ type: object
46
+ example: []
47
+ 400:
48
+ description: Returns "400 Bad Request" if transaction logging is not enabled in the server settings (code `no_transaction_logging`) or if no targets were specified in your query (no _path_ or _for_ parameters given, code `invalid_request`)
49
+ content:
50
+ 'application/json':
51
+ schema:
52
+ $ref: '#/components/schemas/Error'
53
+ example:
54
+ code: no_transaction_logging
55
+ message: Transaction logging not enabled
56
+ 403:
57
+ description: Returns a "403 Forbidden" if the signed in user is not allowed to read from any of the targeted paths
58
+ content:
59
+ 'application/json':
60
+ schema:
61
+ $ref: '#/components/schemas/Error'
62
+ 500:
63
+ description: An unexpected error occurred
64
+ content:
65
+ 'application/json':
66
+ schema:
67
+ $ref: '#/components/schemas/UnexpectedError'
@@ -0,0 +1,82 @@
1
+ /transaction/{dbname}/finish:
2
+ post:
3
+ tags:
4
+ - data
5
+ summary: Finishes a transaction on a path
6
+ description: Finishes a transaction on a path in the database by overwriting it with a new value. NOTE this API endpoint is also available through the websocket connection, which is the preferred method. This API endpoint is provided for clients not supporting websockets, and those that don't have a websocket connection by choice or because of network limitations.
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: transaction details and the new value to store
17
+ content:
18
+ 'application/json':
19
+ schema:
20
+ type: object
21
+ properties:
22
+ id:
23
+ type: string
24
+ description: transaction id returned by the _start_ endpoint
25
+ example: jld2cjxh0000qzrmn831i7rn
26
+ path:
27
+ type: string
28
+ description: the same path used in the _start_ endpoint call
29
+ example: collection/child/property
30
+ value:
31
+ $ref: '#/components/schemas/SerializedValue'
32
+ responses:
33
+ 200:
34
+ description: If successful returns the string `"done"`
35
+ content:
36
+ 'text/plain':
37
+ headers:
38
+ 'AceBase-Context':
39
+ description: Returns the context that was passed to the transaction start endpoint, augmented with an `acebase_cursor` if transaction logging is enabled on the server.
40
+ schema:
41
+ type: string
42
+ example: '{ "acebase_cursor": "l3lf2iwd000109mgdn0d6pqt" }'
43
+ schema:
44
+ type: string
45
+ value: done
46
+ example: done
47
+ description: the string `"done"`
48
+ 400:
49
+ description: Returns "400 Bad Request" if the sent value is incorrect
50
+ content:
51
+ 'application/json':
52
+ schema:
53
+ $ref: '#/components/schemas/Error'
54
+ example:
55
+ code: invalid_serialized_value
56
+ message: The sent value is not properly serialized
57
+ 403:
58
+ description: Returns "403 Forbidden" if the signed in user is not allowed to write to the target path
59
+ content:
60
+ 'application/json':
61
+ schema:
62
+ $ref: '#/components/schemas/Error'
63
+ 410:
64
+ description: Returns "410 Gone" if the specified transaction was not found, timed out, or the path does not match with the one provided in the _start_ endpoint.
65
+ content:
66
+ 'text/plain':
67
+ schema:
68
+ type: string
69
+ value: transaction not found
70
+ example: transaction not found
71
+ 422:
72
+ description: Returns "422 Unprocessable Entity" if schema validation for the sent value failed.
73
+ content:
74
+ 'application/json':
75
+ schema:
76
+ $ref: '#/components/schemas/SchemaValidationError'
77
+ 500:
78
+ description: An unexpected error occurred
79
+ content:
80
+ 'application/json':
81
+ schema:
82
+ $ref: '#/components/schemas/UnexpectedError'
@@ -0,0 +1,58 @@
1
+ /transaction/{dbname}/start:
2
+ post:
3
+ tags:
4
+ - data
5
+ summary: Starts a transaction on a path
6
+ description: Starts a transaction on a path in the database by returning its current value, locking it until the _finish_ endpoint is called. NOTE this API endpoint is also available through the websocket connection, which is the preferred method. This API endpoint is provided for clients not supporting websockets, and those that don't have a websocket connection by choice or because of network limitations.
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ - name: AceBase-Context
16
+ in: header
17
+ description: Contextual info about the database operation (must be valid JSON). This info is included in event notifications sent to clients watching data at this or child paths
18
+ schema:
19
+ type: string
20
+ example: {}
21
+ requestBody:
22
+ description: path to start the transaction on
23
+ content:
24
+ 'application/json':
25
+ schema:
26
+ type: object
27
+ properties:
28
+ path:
29
+ type: string
30
+ description: database path
31
+ example:
32
+ path: collection/child/property
33
+ responses:
34
+ 200:
35
+ description: returns an object with the transaction id, and the current (serialized) value of the given path
36
+ content:
37
+ 'application/json':
38
+ schema:
39
+ type: object
40
+ properties:
41
+ id:
42
+ type: string
43
+ description: transaction id
44
+ example: jld2cjxh0000qzrmn831i7rn
45
+ value:
46
+ $ref: '#/components/schemas/SerializedValue'
47
+ 403:
48
+ description: Returns a "403 Forbidden" if the signed in user is not allowed to write to the target path
49
+ content:
50
+ 'application/json':
51
+ schema:
52
+ $ref: '#/components/schemas/Error'
53
+ 500:
54
+ description: An unexpected error occurred
55
+ content:
56
+ 'application/json':
57
+ schema:
58
+ $ref: '#/components/schemas/UnexpectedError'
@@ -0,0 +1,166 @@
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;
@@ -0,0 +1,84 @@
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;
@@ -0,0 +1,77 @@
1
+ /data/{dbname}/{path}:
2
+ post:
3
+ tags:
4
+ - data
5
+ summary: Update the value of a path
6
+ description: Updates the stored value of a path in the database. If the value is an object, only the given properties are overwritten
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ - name: path
16
+ in: path
17
+ description: database path
18
+ required: true
19
+ schema:
20
+ type: string
21
+ example: collection/child/property
22
+ - name: AceBase-Context
23
+ in: header
24
+ description: Contextual info about the database operation (must be valid JSON). This info is included in event notifications sent to clients watching data at this or child paths
25
+ schema:
26
+ type: string
27
+ example: '{}'
28
+ requestBody:
29
+ description: serialized value to store in the database
30
+ content:
31
+ 'application/json':
32
+ schema:
33
+ $ref: '#/components/schemas/SerializedValue'
34
+ responses:
35
+ 200:
36
+ description: Returns "200 OK" when the database operation succeeded
37
+ content:
38
+ 'application/json':
39
+ headers:
40
+ 'AceBase-Context':
41
+ description: Returns contextual information, such as the `acebase_cursor` if transaction logging is enabled on the server.
42
+ schema:
43
+ type: string
44
+ example: '{ "acebase_cursor": "l3lf2iwd000109mgdn0d6pqt" }'
45
+ schema:
46
+ type: object
47
+ properties:
48
+ success:
49
+ type: boolean
50
+ example: true
51
+ 400:
52
+ description: Returns "400 Bad Request" if the sent value is incorrect
53
+ content:
54
+ 'application/json':
55
+ schema:
56
+ $ref: '#/components/schemas/Error'
57
+ example:
58
+ code: invalid_serialized_value
59
+ message: The sent value is not properly serialized
60
+ 403:
61
+ description: Returns "403 Forbidden" if the signed in user is not allowed to write to the target path
62
+ content:
63
+ 'application/json':
64
+ schema:
65
+ $ref: '#/components/schemas/Error'
66
+ 422:
67
+ description: Returns "422 Unprocessable Entity" if schema validation for the sent value failed.
68
+ content:
69
+ 'application/json':
70
+ schema:
71
+ $ref: '#/components/schemas/SchemaValidationError'
72
+ 500:
73
+ description: An unexpected error occurred
74
+ content:
75
+ 'application/json':
76
+ schema:
77
+ $ref: '#/components/schemas/UnexpectedError'