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,29 +0,0 @@
1
- /auth/{dbname}/state:
2
- get:
3
- tags:
4
- - auth
5
- summary: Get authentication state
6
- description: Gets current auth state
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
- responses:
16
- 200:
17
- description: returns whether the request was authenticated and by which user (determined by the sent Authorization header)
18
- content:
19
- 'application/json':
20
- schema:
21
- type: object
22
- properties:
23
- signed_in:
24
- type: boolean
25
- example: true
26
- user:
27
- $ref: '#/components/schemas/User'
28
- required:
29
- - signed_in
@@ -1,147 +0,0 @@
1
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
2
- import { AceBaseUser, DbUserAccountDetails, getPublicAccountDetails, UserProfilePicture } from '../schema/user';
3
- import { emailExistsError, invalidDisplayNameError, invalidEmailError, invalidPictureError, invalidSettingsError, invalidUsernameError, isValidDisplayName, isValidEmail, isValidNewEmailAddress, isValidNewUsername, isValidPicture, isValidSettings, isValidUsername, usernameExistsError } from '../shared/validate';
4
- import { sendNotAuthenticatedError, sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
5
-
6
- export class UpdateError extends Error {
7
- constructor(public code: 'unauthenticated_update'|'unauthorized_update'|'user_not_found'|'invalid_email'|'email_conflict'|'invalid_username'|'username_conflict'|'invalid_display_name'|'invalid_picture'|'invalid_settings', message: string) {
8
- super(message);
9
- }
10
- }
11
-
12
- export type RequestQuery = {};
13
- export type RequestBody = {
14
- /** admin only: specifies user account to update */
15
- uid: string;
16
- /** Admin only: whether to enable or disable the account */
17
- is_disabled?: boolean;
18
- email?: string;
19
- username?: string;
20
- displayName?: string;
21
- display_name?: string;
22
- picture?: UserProfilePicture;
23
- settings?: {
24
- [name: string]: string|number|boolean
25
- };
26
- } & (
27
- // Allow both spellings of display name. display_name is used in the db, displayName in public user detail server responses.
28
- // displayName is preferred and documented in the OpenAPI docs
29
- { displayName: string; } | { display_name: string; }
30
- );
31
-
32
- export type ResponseBody = { user: AceBaseUser } | { code: UpdateError['code']; message: string };
33
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
34
-
35
- export const addRoute = (env: RouteInitEnvironment) => {
36
- env.app.post(`/auth/${env.db.name}/update`, async (req: Request, res) => {
37
-
38
- let details = req.body;
39
-
40
- if (!req.user) {
41
- env.logRef.push({ action: 'update', success: false, code: 'unauthenticated_update', update_uid: details.uid, ip: req.ip, date: new Date() });
42
- return sendNotAuthenticatedError(res, 'unauthenticated_update', 'Sign in to change details');
43
- }
44
-
45
- const uid = details.uid || req.user.uid;
46
-
47
- if (req.user.uid !== 'admin' && (uid !== req.user.uid || typeof details.is_disabled === 'boolean')) {
48
- env.logRef.push({ action: 'update', success: false, code: 'unauthorized_update', auth_uid: req.user.uid, update_uid: details.uid, ip: req.ip, date: new Date() });
49
- return sendUnauthorizedError(res, 'unauthorized_update', 'You are not authorized to perform this update. This attempt has been logged.');
50
- }
51
-
52
- if (typeof details.display_name === 'undefined' && typeof details.displayName === 'string') {
53
- // Allow displayName to be sent also (which is used in signup endpoint)
54
- details.display_name = details.displayName;
55
- }
56
-
57
- // Check if sent details are ok
58
- let err: { code: UpdateError['code'], message: string };
59
- if (details.email && !isValidEmail(details.email)) {
60
- err = invalidEmailError;
61
- }
62
- else if (details.email && !await isValidNewEmailAddress(env.authRef, details.email)) {
63
- err = emailExistsError;
64
- }
65
- else if (details.username && !isValidUsername(details.username)) {
66
- err = invalidUsernameError;
67
- }
68
- else if (details.username && !await isValidNewUsername(env.authRef, details.username)) {
69
- err = usernameExistsError;
70
- }
71
- else if (details.display_name && !isValidDisplayName(details.display_name)) {
72
- err = invalidDisplayNameError;
73
- }
74
- else if (details.picture && !isValidPicture(details.picture)) {
75
- err = invalidPictureError;
76
- }
77
- else if (!isValidSettings(details.settings)) {
78
- err = invalidSettingsError;
79
- }
80
-
81
- if (err) {
82
- // Log failure
83
- env.logRef.push({ action: 'update', success: false, code: err.code, auth_uid: req.user.uid, update_uid: uid, ip: req.ip, date: new Date() });
84
- res.status(422).send(err); // Unprocessable Entity
85
- return;
86
- }
87
-
88
- try {
89
- let user: DbUserAccountDetails;
90
- await env.authRef.child(uid).transaction(snap => {
91
- if (!snap.exists()) {
92
- throw new UpdateError('user_not_found', `No user found with uid ${uid}`);
93
- }
94
- user = snap.val();
95
- if (details.email && details.email !== user.email) {
96
- user.email = details.email;
97
- user.email_verified = false; // TODO: send verification email
98
- }
99
- if (details.username) { user.username = details.username; }
100
- if (details.display_name) { user.display_name = details.display_name; }
101
- if (details.picture) { user.picture = details.picture; }
102
- if (details.settings) {
103
- if (typeof user.settings !== 'object') {
104
- user.settings = {};
105
- }
106
- Object.keys(details.settings).forEach(key => {
107
- user.settings[key] = details.settings[key];
108
- });
109
- if (!isValidSettings(user.settings)) {
110
- err = invalidSettingsError;
111
- env.logRef.push({ action: 'update', success: false, code: 'too_many_settings', auth_uid: req.user.uid, update_uid: details.uid, ip: req.ip, date: new Date() });
112
- res.statusCode = 422; // Unprocessable Entity
113
- res.send(err);
114
- return;
115
- }
116
- }
117
- if (typeof details.is_disabled === 'boolean') {
118
- user.is_disabled = details.is_disabled;
119
- }
120
-
121
- return user; // Update db user
122
- });
123
-
124
- // Update cache
125
- env.authCache.set(user.uid, user);
126
-
127
- // Send merged results back
128
- res.send({ user: getPublicAccountDetails(user) });
129
- }
130
- catch (err) {
131
-
132
- // All known errors except user_not_found will have been sent already
133
- if (err.code === 'user_not_found') {
134
- env.logRef.push({ action: 'update', success: false, code: err.code, auth_uid: req.user.uid, update_uid: details.uid, ip: req.ip, date: new Date() });
135
-
136
- res.statusCode = 404; // Not Found
137
- res.send(err);
138
- }
139
- else {
140
- // Unexpected
141
- env.logRef.push({ action: 'update', success: false, code: err.code || 'unexpected', message: err.message, auth_uid: req.user.uid, update_uid: details.uid, ip: req.ip, date: new Date() });
142
- sendUnexpectedError(res, err);
143
- }
144
- }
145
-
146
- });
147
- };
@@ -1,152 +0,0 @@
1
- /auth/{dbname}/update:
2
- post:
3
- tags:
4
- - auth
5
- summary: Update user details
6
- description: Updates user account details
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: user details to update
17
- content:
18
- 'application/json':
19
- schema:
20
- type: object
21
- properties:
22
- uid:
23
- type: string
24
- description: (admin user only) to change a user's account settings, the target account `uid` must be passed with the request
25
- is_disabled:
26
- type: boolean
27
- description: (admin user only) whether the target account should be disabled to enable/disable signin
28
- email:
29
- type: string
30
- description: New email address
31
- username:
32
- type: string
33
- description: New username
34
- displayName:
35
- type: string
36
- description: Name of the user for public displaying purposes. Consider this a real name, alias or handle. (NOTE this property is equivalent to the deprecated `display_name`, both are allowed to be used from acebase-server v1.8.1)
37
- display_name:
38
- type: string
39
- description: Name of the user for public displaying purposes. Consider this a real name, alias or handle. (NOTE this property deprecated, use `displayName` instead)
40
- picture:
41
- type: object
42
- description: Profile picture
43
- properties:
44
- url:
45
- type: string
46
- width:
47
- type: number
48
- height:
49
- type: number
50
- example:
51
- url: https://my.profile.pic/me.jpg
52
- width: 500
53
- height: 500
54
- settings:
55
- type: object
56
- otherProperties: true
57
- desciption: (optional) miscellanious other info to store with the user account
58
- required:
59
- - username
60
- - email
61
- - displayName
62
- - password
63
- responses:
64
- 200:
65
- description: When update succeeds, it returns an object with the new user details
66
- content:
67
- 'application/json':
68
- schema:
69
- type: object
70
- properties:
71
- user:
72
- $ref: '#/components/schemas/User'
73
- 401:
74
- description: If this is an unauthenticated request (not signed in), `"401 Unauthorized"` is returned
75
- content:
76
- 'application/json':
77
- schema:
78
- type: object
79
- properties:
80
- code:
81
- type: string
82
- value: unauthenticated_update
83
- message:
84
- type: string
85
- value: Sign in to change details
86
- example:
87
- code: unauthenticated_update
88
- message: Sign in to change details
89
- 403:
90
- description: If a non-admin user tries to update a user's account details, `"403 Forbidden"` is returned
91
- content:
92
- 'application/json':
93
- schema:
94
- type: object
95
- properties:
96
- code:
97
- type: string
98
- value: unauthorized_update
99
- message:
100
- type: string
101
- value: You are not authorized to perform this update. This attempt has been logged.
102
- example:
103
- code: unauthorized_update
104
- message: You are not authorized to perform this update. This attempt has been logged.
105
- 404:
106
- description: User account to update does not exist
107
- content:
108
- 'application/json':
109
- schema:
110
- type: object
111
- properties:
112
- code:
113
- type: string
114
- value: user_not_found
115
- message:
116
- type: string
117
- value: No user found with uid jld2cjxh0000qzrmn831i7rn
118
- example:
119
- code: user_not_found
120
- message: No user found with uid jld2cjxh0000qzrmn831i7rn
121
- 422:
122
- description: When the sent request details are incorrect, this "422 Unprocessable Entity" is returned
123
- content:
124
- 'application/json':
125
- schema:
126
- type: object
127
- properties:
128
- code:
129
- type: string
130
- description: The exact error code
131
- enum:
132
- - invalid_email
133
- - email_conflict
134
- - invalid_username
135
- - username_conflict
136
- - invalid_display_name
137
- - invalid_picture
138
- - invalid_settings
139
- example: user_not_found
140
- message:
141
- type: string
142
- description: Description of the error
143
- example: Account with email address exists already
144
- example:
145
- code: username_conflict
146
- message: Account with username exists already
147
- 500:
148
- description: An unenexpected error occurred on the server
149
- content:
150
- 'application/json':
151
- schema:
152
- $ref: '#/components/schemas/UnexpectedError'
@@ -1,67 +0,0 @@
1
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
2
- import { DbUserAccountDetails } from '../schema/user';
3
- import { parseSignedPublicToken } from '../shared/tokens';
4
- import { sendBadRequestError, sendUnexpectedError } from '../shared/error';
5
-
6
- export class VerifyEmailError extends Error {
7
- constructor(public code: 'invalid_code'|'unknown_user', message: string) {
8
- super(message);
9
- }
10
- }
11
-
12
- export type RequestQuery = {};
13
- export type RequestBody = { code: string };
14
- export type ResponseBody = 'OK' | { code: string; message: string };
15
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
16
-
17
- /**
18
- * Adds the verify_email route and returns the verification function that can be used to manually verify an email address
19
- * @param env environment
20
- * @returns returns the verification function
21
- */
22
- export const addRoute = (env: RouteInitEnvironment) => {
23
-
24
- const verifyEmailAddress = async (clientIp: string, code: string) => {
25
- try {
26
- var verification = parseSignedPublicToken(code, env.tokenSalt);
27
- }
28
- catch (err) {
29
- throw new VerifyEmailError('invalid_code', err.message);
30
- }
31
-
32
- const snap = await env.authRef.child(verification.uid).get();
33
- if (!snap.exists()) {
34
- throw new VerifyEmailError('unknown_user', 'Unknown user');
35
- }
36
- const user: DbUserAccountDetails = snap.val();
37
- user.uid = snap.key as string;
38
-
39
- // No need to do further checks, code was signed by us so we can trust the contents
40
- // Mark account as verified
41
- await snap.ref.update({ email_verified: true });
42
-
43
- env.logRef.push({ action: 'verify_email', success: true, ip: clientIp, date: new Date(), uid: user.uid });
44
- };
45
-
46
- env.app.post(`/auth/${env.db.name}/verify_email`, async (req: Request, res) => {
47
-
48
- const details = req.body;
49
- try {
50
- await verifyEmailAddress(req.ip, details.code);
51
- res.send('OK');
52
- }
53
- catch (err) {
54
- env.logRef.push({ action: 'verify_email', success: false, code: err.code, message: err.message, ip: req.ip, date: new Date(), uid: req.user?.uid ?? null });
55
- if (err.code) {
56
- sendBadRequestError(res, err);
57
- }
58
- else {
59
- sendUnexpectedError(res, err);
60
- }
61
- }
62
- });
63
-
64
- return verifyEmailAddress;
65
- };
66
-
67
- export default addRoute;
@@ -1,53 +0,0 @@
1
- /auth/{dbname}/verify_email:
2
- post:
3
- tags:
4
- - auth
5
- summary: Verifies an email address
6
- description: Verifies an email address with a code sent through their email address
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: verification object
17
- content:
18
- 'application/json':
19
- schema:
20
- type: object
21
- properties:
22
- code:
23
- type: string
24
- description: Verification code that was sent to the user's email address
25
- required:
26
- - code
27
- example:
28
- code: ewrg235235g23gwrvsdb34g524rvqewwrv425gervqew...
29
- responses:
30
- 200:
31
- description: If the email address is successfully verified, returns the string `"OK"`
32
- content:
33
- 'text/plain':
34
- schema:
35
- type: 'string'
36
- value: OK
37
- example: OK
38
- description: The string `"OK"`
39
- 401:
40
- description: Returns a `"401 Bad Request"` if the code sent with the request is invalid
41
- content:
42
- 'application/json':
43
- schema:
44
- $ref: '#/components/schemas/Error'
45
- example:
46
- code: invalid_code
47
- message: Invalid token
48
- 500:
49
- description: An unexpected error occurred
50
- content:
51
- 'application/json':
52
- schema:
53
- $ref: '#/components/schemas/UnexpectedError'
@@ -1,67 +0,0 @@
1
- import { RouteInitEnvironment } from '../shared/env';
2
- import { addMiddleware as addBearerAuthMiddleware } from '../middleware/user';
3
- import { addRoute as addStateRoute } from './auth-state';
4
- import { addRoute as addSignInRoute } from './auth-signin';
5
- import { addRoute as addSignOutRoute } from './auth-signout';
6
- import { addRoute as addVerifyEmailRoute } from './auth-verify-email';
7
- import { addRoute as addResetPasswordRoute } from './auth-reset-password';
8
- import { addRoute as addChangePasswordRoute } from './auth-change-password';
9
- import { addRoute as addSignUpRoute } from './auth-signup';
10
- import { addRoute as addUpdateRoute } from './auth-update';
11
- import { addRoute as addDeleteRoute } from './auth-delete';
12
- import { addRoute as addOAuth2InitRoute } from './oauth2-init';
13
- import { addRoute as addOAuth2SignInRoute } from './oauth2-signin';
14
- import { addRoute as addOAuth2RefreshRoute } from './oauth2-refresh';
15
-
16
- export const addAuthenticionRoutes = (env: RouteInitEnvironment) => {
17
- if (!env.config.auth.enabled) {
18
- throw new Error('Authentication not enabled in the server settings');
19
- }
20
-
21
- // Bearer authentication middleware
22
- addBearerAuthMiddleware(env);
23
-
24
- // Auth state endpoint
25
- addStateRoute(env);
26
-
27
- // signin endpoint
28
- addSignInRoute(env);
29
-
30
- // signout endpoint
31
- addSignOutRoute(env);
32
-
33
- // verify email endpoint
34
- const verifyEmailAddress = addVerifyEmailRoute(env);
35
-
36
- // reset password endpoint
37
- const resetPassword = addResetPasswordRoute(env);
38
-
39
- // change password endpoint
40
- addChangePasswordRoute(env);
41
-
42
- // signup endpoint
43
- addSignUpRoute(env);
44
-
45
- // update enpoint
46
- addUpdateRoute(env);
47
-
48
- // delete endpoint
49
- addDeleteRoute(env);
50
-
51
- // OAuth2 init endpoint
52
- addOAuth2InitRoute(env);
53
-
54
- // OAuth2 signin endpoint
55
- addOAuth2SignInRoute(env);
56
-
57
- // OAuth2 token refresh endpoint
58
- addOAuth2RefreshRoute(env);
59
-
60
- // Return auth functions that can be used directly through an AceBaseServer instance
61
- return {
62
- verifyEmailAddress,
63
- resetPassword
64
- };
65
- };
66
-
67
- export default addAuthenticionRoutes;
@@ -1,31 +0,0 @@
1
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
2
- import { sendUnauthorizedError } from '../shared/error';
3
-
4
- export type RequestQuery = null;
5
- export type RequestBody = null;
6
- export type ResponseBody = { exists: boolean };
7
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
8
-
9
- export const addRoute = (env: RouteInitEnvironment) => {
10
-
11
- env.app.get(`/exists/${env.db.name}/*`, async (req: Request, res) => {
12
- // Exists query
13
- const path = req.path.slice(env.db.name.length + 9);
14
- const access = env.rules.userHasAccess(req.user, path, false);
15
- if (!access.allow) {
16
- return sendUnauthorizedError(res, access.code, access.message);
17
- }
18
-
19
- try {
20
- const exists = await env.db.ref(path).exists();
21
- res.send({ exists });
22
- }
23
- catch(err) {
24
- res.statusCode = 500;
25
- res.send(err);
26
- }
27
- });
28
-
29
- };
30
-
31
- export default addRoute;
@@ -1,44 +0,0 @@
1
- /exists/{dbname}/{path}:
2
- get:
3
- tags:
4
- - data
5
- summary: Get existence of a path
6
- description: Gets the existence of a path in the database
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
- responses:
23
- 200:
24
- description: returns whether the target path exists in the database
25
- content:
26
- 'application/json':
27
- schema:
28
- type: object
29
- properties:
30
- exists:
31
- type: boolean
32
- example: true
33
- 403:
34
- description: Returns a "403 Forbidden" if the signed in user is not allowed to read from the target path
35
- content:
36
- 'application/json':
37
- schema:
38
- $ref: '#/components/schemas/Error'
39
- 500:
40
- description: An unexpected error occurred
41
- content:
42
- 'application/json':
43
- schema:
44
- $ref: '#/components/schemas/UnexpectedError'
@@ -1,51 +0,0 @@
1
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
2
- import { sendUnauthorizedError } from '../shared/error';
3
-
4
- export type RequestQuery = {
5
- format?: 'json';
6
- type_safe?: '0'|'1'
7
- };
8
- export type RequestBody = null;
9
- export type ResponseBody = any;
10
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
11
-
12
- export const addRoute = (env: RouteInitEnvironment) => {
13
-
14
- env.app.get(`/export/${env.db.name}/*`, async (req: Request, res) => {
15
- // Export API
16
- const path = req.path.slice(env.db.name.length + 9);
17
- const access = env.rules.userHasAccess(req.user, path, false);
18
- if (!access.allow) {
19
- return sendUnauthorizedError(res, access.code, access.message);
20
- }
21
- const format = req.query.format || 'json';
22
- const type_safe = req.query.type_safe !== '0';
23
-
24
- const write = async (chunk) => {
25
- let ok = res.write(chunk);
26
- if (!ok) {
27
- await new Promise(resolve => res.once('drain', resolve));
28
- }
29
- };
30
-
31
- const ref = env.db.ref(path);
32
- res.setHeader('Content-Disposition', `attachment; filename=${ref.key || 'export'}.json`); // Will be treated as a download in browser
33
-
34
- try {
35
- await ref.export(write, { format, type_safe });
36
- }
37
- catch (err) {
38
- env.debug.error(`Error exporting data for path "/${path}": `, err);
39
- if (!res.headersSent) {
40
- res.statusCode = 500;
41
- res.send(err);
42
- }
43
- }
44
- finally {
45
- res.end();
46
- }
47
- });
48
-
49
- };
50
-
51
- export default addRoute;