acebase-server 1.11.0 → 1.13.1

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 (342) hide show
  1. package/.vscode/launch.json +24 -0
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/logger.js +74 -0
  4. package/dist/cjs/middleware/admin-only.js +29 -0
  5. package/dist/cjs/middleware/user.js +4 -4
  6. package/dist/cjs/routes/auth-change-password.js +7 -4
  7. package/dist/cjs/routes/auth-delete.js +9 -7
  8. package/dist/cjs/routes/auth-forgot-password.js +9 -6
  9. package/dist/cjs/routes/auth-reset-password.js +5 -3
  10. package/dist/cjs/routes/auth-signout.js +6 -4
  11. package/dist/cjs/routes/auth-signup.js +17 -15
  12. package/dist/cjs/routes/auth-update.js +9 -6
  13. package/dist/cjs/routes/auth-verify-email.js +6 -3
  14. package/dist/cjs/routes/data-index-create.js +3 -5
  15. package/dist/cjs/routes/data-index-delete.js +2 -4
  16. package/dist/cjs/routes/data-index-list.js +2 -4
  17. package/dist/cjs/routes/data-reflect.js +2 -4
  18. package/dist/cjs/routes/data-schema-get.js +2 -4
  19. package/dist/cjs/routes/data-schema-set.js +2 -4
  20. package/dist/cjs/routes/data-schema-test.js +2 -4
  21. package/dist/cjs/routes/data-schemas-list.js +2 -4
  22. package/dist/cjs/routes/data-set.js +8 -7
  23. package/dist/cjs/routes/data-transaction.js +15 -8
  24. package/dist/cjs/routes/data-update.js +8 -6
  25. package/dist/cjs/routes/meta-logs.js +50 -0
  26. package/dist/cjs/routes/meta.js +3 -0
  27. package/dist/cjs/routes/oauth2-signin.js +9 -6
  28. package/dist/cjs/server.js +3 -1
  29. package/dist/cjs/shared/rootpath.js +2 -0
  30. package/dist/cjs/shared/signin.js +8 -3
  31. package/dist/cjs/start.js +3 -0
  32. package/dist/cjs/websocket/index.js +42 -23
  33. package/dist/esm/index.d.ts +1 -0
  34. package/dist/esm/logger.js +52 -0
  35. package/dist/esm/middleware/admin-only.js +25 -0
  36. package/dist/esm/middleware/user.js +4 -4
  37. package/dist/esm/routes/auth-change-password.js +6 -3
  38. package/dist/esm/routes/auth-delete.js +7 -5
  39. package/dist/esm/routes/auth-forgot-password.js +8 -6
  40. package/dist/esm/routes/auth-reset-password.js +4 -2
  41. package/dist/esm/routes/auth-signout.js +4 -2
  42. package/dist/esm/routes/auth-signup.js +12 -10
  43. package/dist/esm/routes/auth-update.js +8 -6
  44. package/dist/esm/routes/auth-verify-email.js +6 -2
  45. package/dist/esm/routes/data-index-create.js +4 -6
  46. package/dist/esm/routes/data-index-delete.js +3 -5
  47. package/dist/esm/routes/data-index-list.js +3 -5
  48. package/dist/esm/routes/data-reflect.js +1 -4
  49. package/dist/esm/routes/data-schema-get.js +3 -5
  50. package/dist/esm/routes/data-schema-set.js +3 -5
  51. package/dist/esm/routes/data-schema-test.js +3 -5
  52. package/dist/esm/routes/data-schemas-list.js +3 -5
  53. package/dist/esm/routes/data-set.js +6 -5
  54. package/dist/esm/routes/data-transaction.js +12 -5
  55. package/dist/esm/routes/data-update.js +6 -4
  56. package/dist/esm/routes/meta-logs.js +36 -0
  57. package/dist/esm/routes/meta.js +3 -0
  58. package/dist/esm/routes/oauth2-signin.js +8 -5
  59. package/dist/esm/server.js +3 -1
  60. package/dist/esm/shared/rootpath.js +2 -0
  61. package/dist/esm/shared/signin.js +7 -3
  62. package/dist/esm/start.js +3 -0
  63. package/dist/esm/websocket/index.js +37 -22
  64. package/dist/types/logger.d.ts +35 -0
  65. package/dist/types/middleware/admin-only.d.ts +19 -0
  66. package/dist/types/routes/meta-logs.d.ts +20 -0
  67. package/dist/types/rules.d.ts +2 -2
  68. package/dist/types/shared/env.d.ts +3 -1
  69. package/dist/types/shared/signin.d.ts +1 -1
  70. package/dist/types/websocket/index.d.ts +4 -0
  71. package/package.json +5 -5
  72. package/webmanager/acebase-client-browser.min.js +16 -16
  73. package/create-package-files +0 -12
  74. package/dist/cjs/auth.js.map +0 -1
  75. package/dist/cjs/cluster.js.map +0 -1
  76. package/dist/cjs/index.js.map +0 -1
  77. package/dist/cjs/middleware/404.js.map +0 -1
  78. package/dist/cjs/middleware/cache.js.map +0 -1
  79. package/dist/cjs/middleware/connection.js.map +0 -1
  80. package/dist/cjs/middleware/context.js.map +0 -1
  81. package/dist/cjs/middleware/cors.js.map +0 -1
  82. package/dist/cjs/middleware/swagger.js.map +0 -1
  83. package/dist/cjs/middleware/user.js.map +0 -1
  84. package/dist/cjs/oauth-providers/dropbox.js.map +0 -1
  85. package/dist/cjs/oauth-providers/facebook.js.map +0 -1
  86. package/dist/cjs/oauth-providers/google.js.map +0 -1
  87. package/dist/cjs/oauth-providers/index.js.map +0 -1
  88. package/dist/cjs/oauth-providers/instagram.js.map +0 -1
  89. package/dist/cjs/oauth-providers/oauth-provider.js.map +0 -1
  90. package/dist/cjs/oauth-providers/spotify.js.map +0 -1
  91. package/dist/cjs/routes/auth-change-password.js.map +0 -1
  92. package/dist/cjs/routes/auth-delete.js.map +0 -1
  93. package/dist/cjs/routes/auth-forgot-password.js.map +0 -1
  94. package/dist/cjs/routes/auth-reset-password.js.map +0 -1
  95. package/dist/cjs/routes/auth-signin.js.map +0 -1
  96. package/dist/cjs/routes/auth-signout.js.map +0 -1
  97. package/dist/cjs/routes/auth-signup.js.map +0 -1
  98. package/dist/cjs/routes/auth-state.js.map +0 -1
  99. package/dist/cjs/routes/auth-update.js.map +0 -1
  100. package/dist/cjs/routes/auth-verify-email.js.map +0 -1
  101. package/dist/cjs/routes/auth.js.map +0 -1
  102. package/dist/cjs/routes/data-exists.js.map +0 -1
  103. package/dist/cjs/routes/data-export.js.map +0 -1
  104. package/dist/cjs/routes/data-get.js.map +0 -1
  105. package/dist/cjs/routes/data-import.js.map +0 -1
  106. package/dist/cjs/routes/data-index-create.js.map +0 -1
  107. package/dist/cjs/routes/data-index-delete.js.map +0 -1
  108. package/dist/cjs/routes/data-index-list.js.map +0 -1
  109. package/dist/cjs/routes/data-query.js.map +0 -1
  110. package/dist/cjs/routes/data-reflect.js.map +0 -1
  111. package/dist/cjs/routes/data-schema-get.js.map +0 -1
  112. package/dist/cjs/routes/data-schema-set.js.map +0 -1
  113. package/dist/cjs/routes/data-schema-test.js.map +0 -1
  114. package/dist/cjs/routes/data-schemas-list.js.map +0 -1
  115. package/dist/cjs/routes/data-set.js.map +0 -1
  116. package/dist/cjs/routes/data-sync-changes.js.map +0 -1
  117. package/dist/cjs/routes/data-sync-mutations.js.map +0 -1
  118. package/dist/cjs/routes/data-transaction.js.map +0 -1
  119. package/dist/cjs/routes/data-update.js.map +0 -1
  120. package/dist/cjs/routes/data.js.map +0 -1
  121. package/dist/cjs/routes/docs.js.map +0 -1
  122. package/dist/cjs/routes/meta-info.js.map +0 -1
  123. package/dist/cjs/routes/meta-ping.js.map +0 -1
  124. package/dist/cjs/routes/meta-stats.js.map +0 -1
  125. package/dist/cjs/routes/meta.js.map +0 -1
  126. package/dist/cjs/routes/oauth2-init.js.map +0 -1
  127. package/dist/cjs/routes/oauth2-refresh.js.map +0 -1
  128. package/dist/cjs/routes/oauth2-signin.js.map +0 -1
  129. package/dist/cjs/routes/webmanager.js.map +0 -1
  130. package/dist/cjs/rules.js.map +0 -1
  131. package/dist/cjs/schema/user.js.map +0 -1
  132. package/dist/cjs/server.js.map +0 -1
  133. package/dist/cjs/settings/email.js.map +0 -1
  134. package/dist/cjs/settings/index.js.map +0 -1
  135. package/dist/cjs/shared/clients.js.map +0 -1
  136. package/dist/cjs/shared/email.js.map +0 -1
  137. package/dist/cjs/shared/env.js.map +0 -1
  138. package/dist/cjs/shared/error.js.map +0 -1
  139. package/dist/cjs/shared/http.js.map +0 -1
  140. package/dist/cjs/shared/password.js.map +0 -1
  141. package/dist/cjs/shared/rootpath.js.map +0 -1
  142. package/dist/cjs/shared/signin.js.map +0 -1
  143. package/dist/cjs/shared/simple-fetch.js.map +0 -1
  144. package/dist/cjs/shared/tokens.js.map +0 -1
  145. package/dist/cjs/shared/validate.js.map +0 -1
  146. package/dist/cjs/start.js.map +0 -1
  147. package/dist/cjs/test.js.map +0 -1
  148. package/dist/cjs/websocket/index.js.map +0 -1
  149. package/dist/cjs/websocket/manager.js.map +0 -1
  150. package/dist/cjs/websocket/socket.io.js.map +0 -1
  151. package/dist/esm/auth.js.map +0 -1
  152. package/dist/esm/cluster.js.map +0 -1
  153. package/dist/esm/index.js.map +0 -1
  154. package/dist/esm/middleware/404.js.map +0 -1
  155. package/dist/esm/middleware/cache.js.map +0 -1
  156. package/dist/esm/middleware/connection.js.map +0 -1
  157. package/dist/esm/middleware/context.js.map +0 -1
  158. package/dist/esm/middleware/cors.js.map +0 -1
  159. package/dist/esm/middleware/swagger.js.map +0 -1
  160. package/dist/esm/middleware/user.js.map +0 -1
  161. package/dist/esm/oauth-providers/dropbox.js.map +0 -1
  162. package/dist/esm/oauth-providers/facebook.js.map +0 -1
  163. package/dist/esm/oauth-providers/google.js.map +0 -1
  164. package/dist/esm/oauth-providers/index.js.map +0 -1
  165. package/dist/esm/oauth-providers/instagram.js.map +0 -1
  166. package/dist/esm/oauth-providers/oauth-provider.js.map +0 -1
  167. package/dist/esm/oauth-providers/spotify.js.map +0 -1
  168. package/dist/esm/routes/auth-change-password.js.map +0 -1
  169. package/dist/esm/routes/auth-delete.js.map +0 -1
  170. package/dist/esm/routes/auth-forgot-password.js.map +0 -1
  171. package/dist/esm/routes/auth-reset-password.js.map +0 -1
  172. package/dist/esm/routes/auth-signin.js.map +0 -1
  173. package/dist/esm/routes/auth-signout.js.map +0 -1
  174. package/dist/esm/routes/auth-signup.js.map +0 -1
  175. package/dist/esm/routes/auth-state.js.map +0 -1
  176. package/dist/esm/routes/auth-update.js.map +0 -1
  177. package/dist/esm/routes/auth-verify-email.js.map +0 -1
  178. package/dist/esm/routes/auth.js.map +0 -1
  179. package/dist/esm/routes/data-exists.js.map +0 -1
  180. package/dist/esm/routes/data-export.js.map +0 -1
  181. package/dist/esm/routes/data-get.js.map +0 -1
  182. package/dist/esm/routes/data-import.js.map +0 -1
  183. package/dist/esm/routes/data-index-create.js.map +0 -1
  184. package/dist/esm/routes/data-index-delete.js.map +0 -1
  185. package/dist/esm/routes/data-index-list.js.map +0 -1
  186. package/dist/esm/routes/data-query.js.map +0 -1
  187. package/dist/esm/routes/data-reflect.js.map +0 -1
  188. package/dist/esm/routes/data-schema-get.js.map +0 -1
  189. package/dist/esm/routes/data-schema-set.js.map +0 -1
  190. package/dist/esm/routes/data-schema-test.js.map +0 -1
  191. package/dist/esm/routes/data-schemas-list.js.map +0 -1
  192. package/dist/esm/routes/data-set.js.map +0 -1
  193. package/dist/esm/routes/data-sync-changes.js.map +0 -1
  194. package/dist/esm/routes/data-sync-mutations.js.map +0 -1
  195. package/dist/esm/routes/data-transaction.js.map +0 -1
  196. package/dist/esm/routes/data-update.js.map +0 -1
  197. package/dist/esm/routes/data.js.map +0 -1
  198. package/dist/esm/routes/docs.js.map +0 -1
  199. package/dist/esm/routes/meta-info.js.map +0 -1
  200. package/dist/esm/routes/meta-ping.js.map +0 -1
  201. package/dist/esm/routes/meta-stats.js.map +0 -1
  202. package/dist/esm/routes/meta.js.map +0 -1
  203. package/dist/esm/routes/oauth2-init.js.map +0 -1
  204. package/dist/esm/routes/oauth2-refresh.js.map +0 -1
  205. package/dist/esm/routes/oauth2-signin.js.map +0 -1
  206. package/dist/esm/routes/webmanager.js.map +0 -1
  207. package/dist/esm/rules.js.map +0 -1
  208. package/dist/esm/schema/user.js.map +0 -1
  209. package/dist/esm/server.js.map +0 -1
  210. package/dist/esm/settings/email.js.map +0 -1
  211. package/dist/esm/settings/index.js.map +0 -1
  212. package/dist/esm/shared/clients.js.map +0 -1
  213. package/dist/esm/shared/email.js.map +0 -1
  214. package/dist/esm/shared/env.js.map +0 -1
  215. package/dist/esm/shared/error.js.map +0 -1
  216. package/dist/esm/shared/http.js.map +0 -1
  217. package/dist/esm/shared/password.js.map +0 -1
  218. package/dist/esm/shared/rootpath.js.map +0 -1
  219. package/dist/esm/shared/signin.js.map +0 -1
  220. package/dist/esm/shared/simple-fetch.js.map +0 -1
  221. package/dist/esm/shared/tokens.js.map +0 -1
  222. package/dist/esm/shared/validate.js.map +0 -1
  223. package/dist/esm/start.js.map +0 -1
  224. package/dist/esm/test.js.map +0 -1
  225. package/dist/esm/websocket/index.js.map +0 -1
  226. package/dist/esm/websocket/manager.js.map +0 -1
  227. package/dist/esm/websocket/socket.io.js.map +0 -1
  228. package/src/auth.ts +0 -87
  229. package/src/cluster.ts +0 -62
  230. package/src/index.ts +0 -4
  231. package/src/middleware/404.ts +0 -13
  232. package/src/middleware/cache.ts +0 -15
  233. package/src/middleware/connection.ts +0 -48
  234. package/src/middleware/context.ts +0 -23
  235. package/src/middleware/cors.ts +0 -49
  236. package/src/middleware/swagger.ts +0 -19
  237. package/src/middleware/user.ts +0 -51
  238. package/src/oauth-providers/dropbox.ts +0 -144
  239. package/src/oauth-providers/facebook.ts +0 -103
  240. package/src/oauth-providers/google.ts +0 -147
  241. package/src/oauth-providers/index.ts +0 -21
  242. package/src/oauth-providers/instagram.ts +0 -98
  243. package/src/oauth-providers/oauth-provider.ts +0 -65
  244. package/src/oauth-providers/spotify.ts +0 -127
  245. package/src/placeholder.d.ts +0 -12
  246. package/src/routes/auth-change-password.ts +0 -89
  247. package/src/routes/auth-change-password.yaml +0 -74
  248. package/src/routes/auth-delete.ts +0 -47
  249. package/src/routes/auth-delete.yaml +0 -78
  250. package/src/routes/auth-forgot-password.ts +0 -73
  251. package/src/routes/auth-forgot-password.yaml +0 -50
  252. package/src/routes/auth-reset-password.ts +0 -93
  253. package/src/routes/auth-reset-password.yaml +0 -54
  254. package/src/routes/auth-signin.ts +0 -55
  255. package/src/routes/auth-signin.yaml +0 -130
  256. package/src/routes/auth-signout.ts +0 -61
  257. package/src/routes/auth-signout.yaml +0 -46
  258. package/src/routes/auth-signup.ts +0 -161
  259. package/src/routes/auth-signup.yaml +0 -136
  260. package/src/routes/auth-state.ts +0 -20
  261. package/src/routes/auth-state.yaml +0 -29
  262. package/src/routes/auth-update.ts +0 -147
  263. package/src/routes/auth-update.yaml +0 -152
  264. package/src/routes/auth-verify-email.ts +0 -67
  265. package/src/routes/auth-verify-email.yaml +0 -53
  266. package/src/routes/auth.ts +0 -67
  267. package/src/routes/data-exists.ts +0 -31
  268. package/src/routes/data-exists.yaml +0 -44
  269. package/src/routes/data-export.ts +0 -51
  270. package/src/routes/data-export.yaml +0 -64
  271. package/src/routes/data-get.ts +0 -68
  272. package/src/routes/data-get.yaml +0 -54
  273. package/src/routes/data-import.ts +0 -56
  274. package/src/routes/data-import.yaml +0 -75
  275. package/src/routes/data-index-create.ts +0 -85
  276. package/src/routes/data-index-create.yaml +0 -105
  277. package/src/routes/data-index-delete.ts +0 -39
  278. package/src/routes/data-index-delete.yaml +0 -51
  279. package/src/routes/data-index-list.ts +0 -42
  280. package/src/routes/data-index-list.yaml +0 -80
  281. package/src/routes/data-query.ts +0 -97
  282. package/src/routes/data-query.yaml +0 -166
  283. package/src/routes/data-reflect.ts +0 -94
  284. package/src/routes/data-reflect.yaml +0 -124
  285. package/src/routes/data-schema-get.ts +0 -38
  286. package/src/routes/data-schema-get.yaml +0 -53
  287. package/src/routes/data-schema-set.ts +0 -38
  288. package/src/routes/data-schema-set.yaml +0 -60
  289. package/src/routes/data-schema-test.ts +0 -53
  290. package/src/routes/data-schema-test.yaml +0 -66
  291. package/src/routes/data-schemas-list.ts +0 -33
  292. package/src/routes/data-schemas-list.yaml +0 -41
  293. package/src/routes/data-set.ts +0 -80
  294. package/src/routes/data-set.yaml +0 -77
  295. package/src/routes/data-sync-changes.ts +0 -78
  296. package/src/routes/data-sync-changes.yaml +0 -67
  297. package/src/routes/data-sync-mutations.ts +0 -78
  298. package/src/routes/data-sync-mutations.yaml +0 -67
  299. package/src/routes/data-transaction-finish.yaml +0 -82
  300. package/src/routes/data-transaction-start.yaml +0 -58
  301. package/src/routes/data-transaction.ts +0 -159
  302. package/src/routes/data-update.ts +0 -81
  303. package/src/routes/data-update.yaml +0 -77
  304. package/src/routes/data.ts +0 -79
  305. package/src/routes/docs.ts +0 -249
  306. package/src/routes/meta-info.ts +0 -80
  307. package/src/routes/meta-info.yaml +0 -41
  308. package/src/routes/meta-ping.ts +0 -15
  309. package/src/routes/meta-ping.yaml +0 -23
  310. package/src/routes/meta-stats.ts +0 -31
  311. package/src/routes/meta-stats.yaml +0 -41
  312. package/src/routes/meta.ts +0 -18
  313. package/src/routes/oauth2-init.ts +0 -44
  314. package/src/routes/oauth2-init.yaml +0 -63
  315. package/src/routes/oauth2-refresh.ts +0 -39
  316. package/src/routes/oauth2-refresh.yaml +0 -65
  317. package/src/routes/oauth2-signin.ts +0 -282
  318. package/src/routes/oauth2-signin.yaml +0 -66
  319. package/src/routes/webmanager.ts +0 -29
  320. package/src/rules.ts +0 -196
  321. package/src/schema/user.ts +0 -99
  322. package/src/server.ts +0 -418
  323. package/src/settings/email.ts +0 -18
  324. package/src/settings/index.ts +0 -241
  325. package/src/shared/clients.ts +0 -31
  326. package/src/shared/email.ts +0 -33
  327. package/src/shared/env.ts +0 -38
  328. package/src/shared/error.ts +0 -37
  329. package/src/shared/http.ts +0 -26
  330. package/src/shared/password.ts +0 -41
  331. package/src/shared/rootpath.ts +0 -15
  332. package/src/shared/signin.ts +0 -143
  333. package/src/shared/simple-fetch.ts +0 -65
  334. package/src/shared/tokens.ts +0 -77
  335. package/src/shared/validate.ts +0 -53
  336. package/src/start.ts +0 -45
  337. package/src/test.ts +0 -10
  338. package/src/websocket/index.ts +0 -320
  339. package/src/websocket/manager.ts +0 -46
  340. package/src/websocket/socket.io.ts +0 -90
  341. package/tsconfig-cjs.json +0 -10
  342. package/tsconfig.json +0 -21
@@ -1,67 +0,0 @@
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'
@@ -1,82 +0,0 @@
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'
@@ -1,58 +0,0 @@
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'
@@ -1,159 +0,0 @@
1
- import { SchemaValidationError } from 'acebase';
2
- import { ID, Transport } from 'acebase-core';
3
- import { Api } from 'acebase-core/src/api';
4
- import { SerializedValue } from 'acebase-core/types/transport';
5
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
6
- import { sendBadRequestError, sendError, sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
7
-
8
- export const TRANSACTION_TIMEOUT_MS = 10000; // 10s to finish a started transaction
9
-
10
- export class DataTransactionError extends Error {
11
- constructor(public code: 'invalid_serialized_value', message: string) {
12
- super(message);
13
- }
14
- }
15
-
16
- export type ApiTransactionDetails = {
17
- id: string;
18
- value: SerializedValue;
19
- };
20
- export type StartRequestQuery = null;
21
- export type StartRequestBody = {
22
- path: string;
23
- };
24
- export type StartResponseBody = ApiTransactionDetails // 200
25
- | { code: string, message: string } // 403
26
- | { code: 'unexpected', message: string }; // 500
27
- export type StartRequest = RouteRequest<any, StartResponseBody, StartRequestBody, StartRequestQuery>;
28
-
29
- export type FinishRequestQuery = null;
30
- export type FinishRequestBody = ApiTransactionDetails & { path: string };
31
- export type FinishResponseBody = 'done' // 200
32
- | { code: string, message: string } // 400, 403
33
- | 'transaction not found' // 410
34
- | string // 500
35
-
36
- export type FinishRequest = RouteRequest<any, FinishResponseBody, FinishRequestBody, FinishRequestQuery>;
37
-
38
- type Transaction = { id: string; started: number; path: string; context: any; finish?: (val?: any) => ReturnType<Api['transaction']>; timeout: NodeJS.Timeout };
39
-
40
- export const addRoutes = (env: RouteInitEnvironment) => {
41
-
42
- const _transactions = new Map<string, Transaction>();
43
-
44
- // Start transaction endpoint:
45
- env.app.post(`/transaction/${env.db.name}/start`, (req: StartRequest, res) => {
46
- const data = req.body;
47
- const access = env.rules.userHasAccess(req.user, data.path, true);
48
- if (!access.allow) {
49
- return sendUnauthorizedError(res, access.code, access.message);
50
- }
51
-
52
- // Start transaction
53
- const tx: Transaction = {
54
- id: ID.generate(),
55
- started: Date.now(),
56
- path: data.path,
57
- context: req.context,
58
- finish: undefined,
59
- timeout: setTimeout(() => {
60
- _transactions.delete(tx.id);
61
- tx.finish(); // Finish without value cancels the transaction
62
- }, TRANSACTION_TIMEOUT_MS)
63
- };
64
- _transactions.set(tx.id, tx);
65
-
66
- try {
67
- env.debug.verbose(`Transaction ${tx.id} starting...`);
68
-
69
- // const ref = db.ref(tx.path);
70
- const donePromise = env.db.api.transaction(tx.path, val => {
71
- env.debug.verbose(`Transaction ${tx.id} started with value: `, val);
72
- const currentValue = Transport.serialize(val);
73
- const promise = new Promise<any>((resolve) => {
74
- tx.finish = (val: any) => {
75
- env.debug.verbose(`Transaction ${tx.id} finishing with value: `, val);
76
- _transactions.delete(tx.id);
77
- resolve(val);
78
- return donePromise;
79
- };
80
- });
81
- res.send({ id: tx.id, value: currentValue });
82
- return promise;
83
- }, { context: tx.context });
84
- }
85
- catch (err) {
86
- env.debug.error(`failed to start transaction on "${tx.path}":`, err);
87
- env.logRef?.push({ action: 'tx_start', success: false, code: err.code ?? 'unknown_error', path: tx.path, error: err.message, ip: req.ip, uid: req.user?.uid ?? null });
88
- sendUnexpectedError(res, err);
89
- }
90
- });
91
-
92
- // Finish transaction endpoint:
93
- env.app.post(`/transaction/${env.db.name}/finish`, async (req: FinishRequest, res) => {
94
- const data = req.body;
95
-
96
- const tx = _transactions.get(data.id);
97
- if (!tx || tx.path !== data.path) {
98
- res.statusCode = 410; // Gone
99
- res.send(`transaction not found`);
100
- return;
101
- }
102
- clearTimeout(tx.timeout);
103
- _transactions.delete(tx.id);
104
-
105
- const access = env.rules.userHasAccess(req.user, tx.path, true);
106
- if (!access.allow) {
107
- return sendUnauthorizedError(res, access.code, access.message);
108
- }
109
-
110
- // Finish transaction
111
- try {
112
- let cancel = false;
113
- if (typeof data.value === 'object' && (data.value === null || Object.keys(data.value).length === 0)) {
114
- // Returning undefined from a transaction callback should cancel the transaction
115
- // acebase-client (Transport.serialize) serializes value undefined as { val: undefined, map: undefined }, which
116
- // then is sent to the server as an empty object: {}
117
- cancel = true;
118
- }
119
- else if (typeof data.value?.val === 'undefined' || !['string','object','undefined'].includes(typeof data.value?.map)) {
120
- throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
121
- }
122
- const newValue = cancel ? undefined : Transport.deserialize(data.value);
123
-
124
- if (tx.path === '' && req.user?.uid !== 'admin' && newValue !== null && typeof newValue === 'object') {
125
- // Non-admin user: remove any private properties from the update object
126
- Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
127
- }
128
-
129
-
130
- const result = await tx.finish(newValue);
131
-
132
- // NEW: capture cursor and return it in the response context header
133
- if (!tx.context) { tx.context = {}; }
134
- tx.context.acebase_cursor = result.cursor;
135
- res.setHeader('AceBase-Context', JSON.stringify(tx.context));
136
-
137
- res.send('done');
138
- }
139
- catch (err) {
140
- tx.finish(); // Finish without value cancels the transaction
141
- if (err instanceof SchemaValidationError) {
142
- env.logRef?.push({ action: 'tx_finish', success: false, code: 'schema_validation_failed', path: tx.path, error: err.reason, ip: req.ip, uid: req.user?.uid ?? null });
143
- res.status(422).send({ code: 'schema_validation_failed', message: err.message });
144
- }
145
- else if (err instanceof DataTransactionError) {
146
- env.logRef?.push({ action: 'tx_finish', success: false, code: err.code, path: tx.path, ip: req.ip, uid: req.user?.uid ?? null });
147
- sendBadRequestError(res, err);
148
- }
149
- else {
150
- env.debug.error(`failed to finsih transaction on "${tx.path}":`, err);
151
- env.logRef?.push({ action: 'tx_finish', success: false, code: 'unknown_error', path: tx.path, error: err.message, ip: req.ip, uid: req.user?.uid ?? null });
152
- sendError(res, err);
153
- }
154
- }
155
- });
156
-
157
- };
158
-
159
- export default addRoutes;
@@ -1,81 +0,0 @@
1
- import { SchemaValidationError } from 'acebase';
2
- import { Transport } from 'acebase-core';
3
- import { SerializedValue } from 'acebase-core/types/transport';
4
- import { RuleValidationFailCode } from '../rules';
5
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
6
- import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
7
-
8
- export class UpdateDataError extends Error {
9
- constructor(public code: 'invalid_serialized_value', message: string) {
10
- super(message);
11
- }
12
- }
13
-
14
- export type RequestQuery = null;
15
- export type RequestBody = SerializedValue; //{ val: any; map?: string|Record<string, 'date'|'binary'|'reference'|'regexp'|'array'> };
16
- export type ResponseBody = { success: true } // 200
17
- | { code: 'invalid_serialized_value', message: string } // 400
18
- | { code: RuleValidationFailCode, message: string } // 403
19
- | { code: 'schema_validation_failed', message: string } // 422
20
- | { code: string, message: string } // 500
21
-
22
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
23
-
24
- export const addRoute = (env: RouteInitEnvironment) => {
25
-
26
- env.app.post(`/data/${env.db.name}/*`, async (req: Request, res) => {
27
- // update data
28
- const path = req.path.slice(env.db.name.length + 7);
29
- const access = env.rules.userHasAccess(req.user, path, true);
30
- if (!access.allow) {
31
- return sendUnauthorizedError(res, access.code, access.message);
32
- }
33
-
34
- try {
35
- const data = req.body;
36
- if (typeof data?.val === 'undefined' || !['string','object','undefined'].includes(typeof data?.map)) {
37
- throw new UpdateDataError('invalid_serialized_value', 'The sent value is not properly serialized');
38
- }
39
- const val = Transport.deserialize(data);
40
-
41
- if (path === '' && req.user?.uid !== 'admin' && val !== null && typeof val === 'object') {
42
- // Non-admin user: remove any private properties from the update object
43
- Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
44
- }
45
-
46
- // Schema validation moved to storage, no need to check here but an early check won't do no harm!
47
- const validation = await env.db.schema.check(path, val, true);
48
- if (!validation.ok) {
49
- throw new SchemaValidationError(validation.reason);
50
- }
51
-
52
- await env.db.ref(path)
53
- .context(req.context)
54
- .update(val);
55
-
56
- // NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
57
- const returnContext = { acebase_cursor: req.context.acebase_cursor };
58
- res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
59
-
60
- res.send({ success: true });
61
- }
62
- catch(err) {
63
- if (err instanceof SchemaValidationError) {
64
- env.logRef?.push({ action: 'update_data', success: false, code: 'schema_validation_failed', path, error: err.reason, ip: req.ip, uid: req.user?.uid ?? null });
65
- res.status(422).send({ code: 'schema_validation_failed', message: err.message });
66
- }
67
- else if (err instanceof UpdateDataError) {
68
- env.logRef?.push({ action: 'update_data', success: false, code: err.code, path, ip: req.ip, uid: req.user?.uid ?? null });
69
- sendBadRequestError(res, err);
70
- }
71
- else {
72
- env.debug.error(`failed to update "${path}":`, err);
73
- env.logRef?.push({ action: 'update_data', success: false, code: `unknown_error`, path, error: err.message, ip: req.ip, uid: req.user?.uid ?? null });
74
- sendError(res, err);
75
- }
76
- }
77
- });
78
-
79
- };
80
-
81
- export default addRoute;
@@ -1,77 +0,0 @@
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'
@@ -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;