acebase-server 1.8.0 → 1.10.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 (509) hide show
  1. package/.vscode/launch.json +24 -0
  2. package/create-package-files +12 -0
  3. package/dist/cjs/auth.js +89 -0
  4. package/dist/cjs/auth.js.map +1 -0
  5. package/dist/cjs/cluster.js +57 -0
  6. package/dist/cjs/cluster.js.map +1 -0
  7. package/dist/cjs/index.js +9 -0
  8. package/dist/cjs/index.js.map +1 -0
  9. package/dist/cjs/middleware/404.js +15 -0
  10. package/dist/cjs/middleware/404.js.map +1 -0
  11. package/dist/cjs/middleware/cache.js +15 -0
  12. package/dist/cjs/middleware/cache.js.map +1 -0
  13. package/dist/cjs/middleware/connection.js +50 -0
  14. package/dist/cjs/middleware/connection.js.map +1 -0
  15. package/dist/cjs/middleware/context.js +21 -0
  16. package/dist/cjs/middleware/context.js.map +1 -0
  17. package/dist/cjs/middleware/cors.js +51 -0
  18. package/dist/cjs/middleware/cors.js.map +1 -0
  19. package/dist/cjs/middleware/swagger.js +18 -0
  20. package/dist/cjs/middleware/swagger.js.map +1 -0
  21. package/dist/cjs/middleware/user.js +58 -0
  22. package/dist/cjs/middleware/user.js.map +1 -0
  23. package/dist/cjs/oauth-providers/dropbox.js +109 -0
  24. package/dist/cjs/oauth-providers/dropbox.js.map +1 -0
  25. package/dist/cjs/oauth-providers/facebook.js +85 -0
  26. package/dist/cjs/oauth-providers/facebook.js.map +1 -0
  27. package/dist/cjs/oauth-providers/google.js +125 -0
  28. package/dist/cjs/oauth-providers/google.js.map +1 -0
  29. package/dist/cjs/oauth-providers/index.js +27 -0
  30. package/dist/cjs/oauth-providers/index.js.map +1 -0
  31. package/dist/cjs/oauth-providers/instagram.js +80 -0
  32. package/dist/cjs/oauth-providers/instagram.js.map +1 -0
  33. package/dist/cjs/oauth-providers/oauth-provider.js +3 -0
  34. package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -0
  35. package/dist/cjs/oauth-providers/spotify.js +113 -0
  36. package/dist/cjs/oauth-providers/spotify.js.map +1 -0
  37. package/dist/cjs/package.json +3 -0
  38. package/dist/cjs/routes/auth-change-password.js +85 -0
  39. package/dist/cjs/routes/auth-change-password.js.map +1 -0
  40. package/dist/cjs/routes/auth-delete.js +51 -0
  41. package/dist/cjs/routes/auth-delete.js.map +1 -0
  42. package/dist/cjs/routes/auth-forgot-password.js +75 -0
  43. package/dist/cjs/routes/auth-forgot-password.js.map +1 -0
  44. package/dist/cjs/routes/auth-reset-password.js +94 -0
  45. package/dist/cjs/routes/auth-reset-password.js.map +1 -0
  46. package/dist/cjs/routes/auth-signin.js +47 -0
  47. package/dist/cjs/routes/auth-signin.js.map +1 -0
  48. package/dist/cjs/routes/auth-signout.js +60 -0
  49. package/dist/cjs/routes/auth-signout.js.map +1 -0
  50. package/dist/cjs/routes/auth-signup.js +141 -0
  51. package/dist/cjs/routes/auth-signup.js.map +1 -0
  52. package/dist/cjs/routes/auth-state.js +26 -0
  53. package/dist/cjs/routes/auth-state.js.map +1 -0
  54. package/dist/cjs/routes/auth-update.js +129 -0
  55. package/dist/cjs/routes/auth-update.js.map +1 -0
  56. package/dist/cjs/routes/auth-verify-email.js +67 -0
  57. package/dist/cjs/routes/auth-verify-email.js.map +1 -0
  58. package/dist/cjs/routes/auth.js +55 -0
  59. package/dist/cjs/routes/auth.js.map +1 -0
  60. package/dist/cjs/routes/data-exists.js +34 -0
  61. package/dist/cjs/routes/data-exists.js.map +1 -0
  62. package/dist/cjs/routes/data-export.js +49 -0
  63. package/dist/cjs/routes/data-export.js.map +1 -0
  64. package/dist/cjs/routes/data-get.js +67 -0
  65. package/dist/cjs/routes/data-get.js.map +1 -0
  66. package/dist/cjs/routes/data-import.js +55 -0
  67. package/dist/cjs/routes/data-import.js.map +1 -0
  68. package/dist/cjs/routes/data-index-create.js +45 -0
  69. package/dist/cjs/routes/data-index-create.js.map +1 -0
  70. package/dist/cjs/routes/data-index-delete.js +36 -0
  71. package/dist/cjs/routes/data-index-delete.js.map +1 -0
  72. package/dist/cjs/routes/data-index-list.js +35 -0
  73. package/dist/cjs/routes/data-index-list.js.map +1 -0
  74. package/dist/cjs/routes/data-query.js +71 -0
  75. package/dist/cjs/routes/data-query.js.map +1 -0
  76. package/dist/cjs/routes/data-reflect.js +89 -0
  77. package/dist/cjs/routes/data-reflect.js.map +1 -0
  78. package/dist/cjs/routes/data-schema-get.js +39 -0
  79. package/dist/cjs/routes/data-schema-get.js.map +1 -0
  80. package/dist/cjs/routes/data-schema-set.js +33 -0
  81. package/dist/cjs/routes/data-schema-set.js.map +1 -0
  82. package/dist/cjs/routes/data-schema-test.js +46 -0
  83. package/dist/cjs/routes/data-schema-test.js.map +1 -0
  84. package/dist/cjs/routes/data-schemas-list.js +35 -0
  85. package/dist/cjs/routes/data-schemas-list.js.map +1 -0
  86. package/dist/cjs/routes/data-set.js +72 -0
  87. package/dist/cjs/routes/data-set.js.map +1 -0
  88. package/dist/cjs/routes/data-sync-changes.js +68 -0
  89. package/dist/cjs/routes/data-sync-changes.js.map +1 -0
  90. package/dist/cjs/routes/data-sync-mutations.js +68 -0
  91. package/dist/cjs/routes/data-sync-mutations.js.map +1 -0
  92. package/dist/cjs/routes/data-transaction.js +120 -0
  93. package/dist/cjs/routes/data-transaction.js.map +1 -0
  94. package/dist/cjs/routes/data-update.js +71 -0
  95. package/dist/cjs/routes/data-update.js.map +1 -0
  96. package/dist/cjs/routes/data.js +63 -0
  97. package/dist/cjs/routes/data.js.map +1 -0
  98. package/dist/cjs/routes/docs.js +249 -0
  99. package/dist/cjs/routes/docs.js.map +1 -0
  100. package/dist/cjs/routes/meta-info.js +70 -0
  101. package/dist/cjs/routes/meta-info.js.map +1 -0
  102. package/dist/cjs/routes/meta-ping.js +12 -0
  103. package/dist/cjs/routes/meta-ping.js.map +1 -0
  104. package/dist/cjs/routes/meta-stats.js +28 -0
  105. package/dist/cjs/routes/meta-stats.js.map +1 -0
  106. package/dist/cjs/routes/meta.js +17 -0
  107. package/dist/cjs/routes/meta.js.map +1 -0
  108. package/dist/cjs/routes/oauth2-init.js +52 -0
  109. package/dist/cjs/routes/oauth2-init.js.map +1 -0
  110. package/dist/cjs/routes/oauth2-refresh.js +43 -0
  111. package/dist/cjs/routes/oauth2-refresh.js.map +1 -0
  112. package/dist/cjs/routes/oauth2-signin.js +262 -0
  113. package/dist/cjs/routes/oauth2-signin.js.map +1 -0
  114. package/dist/cjs/routes/webmanager.js +27 -0
  115. package/dist/cjs/routes/webmanager.js.map +1 -0
  116. package/dist/cjs/rules.js +175 -0
  117. package/dist/cjs/rules.js.map +1 -0
  118. package/dist/cjs/schema/user.js +26 -0
  119. package/dist/cjs/schema/user.js.map +1 -0
  120. package/dist/cjs/server.js +363 -0
  121. package/dist/cjs/server.js.map +1 -0
  122. package/dist/cjs/settings/email.js +5 -0
  123. package/dist/cjs/settings/email.js.map +1 -0
  124. package/dist/cjs/settings/index.js +159 -0
  125. package/dist/cjs/settings/index.js.map +1 -0
  126. package/dist/cjs/shared/clients.js +27 -0
  127. package/dist/cjs/shared/clients.js.map +1 -0
  128. package/dist/cjs/shared/email.js +7 -0
  129. package/dist/cjs/shared/email.js.map +1 -0
  130. package/{src/oauth-providers/oauth-provider.js → dist/cjs/shared/env.js} +3 -0
  131. package/dist/cjs/shared/env.js.map +1 -0
  132. package/dist/cjs/shared/error.js +35 -0
  133. package/dist/cjs/shared/error.js.map +1 -0
  134. package/dist/cjs/shared/http.js +21 -0
  135. package/dist/cjs/shared/http.js.map +1 -0
  136. package/dist/cjs/shared/password.js +46 -0
  137. package/dist/cjs/shared/password.js.map +1 -0
  138. package/dist/cjs/shared/rootpath.js +15 -0
  139. package/dist/cjs/shared/rootpath.js.map +1 -0
  140. package/dist/cjs/shared/signin.js +139 -0
  141. package/dist/cjs/shared/signin.js.map +1 -0
  142. package/dist/cjs/shared/simple-fetch.js +77 -0
  143. package/dist/cjs/shared/simple-fetch.js.map +1 -0
  144. package/dist/cjs/shared/tokens.js +79 -0
  145. package/dist/cjs/shared/tokens.js.map +1 -0
  146. package/dist/cjs/shared/validate.js +62 -0
  147. package/dist/cjs/shared/validate.js.map +1 -0
  148. package/dist/cjs/start.js +51 -0
  149. package/dist/cjs/start.js.map +1 -0
  150. package/dist/cjs/test.js +11 -0
  151. package/dist/cjs/test.js.map +1 -0
  152. package/dist/cjs/websocket/index.js +301 -0
  153. package/dist/cjs/websocket/index.js.map +1 -0
  154. package/dist/cjs/websocket/manager.js +16 -0
  155. package/dist/cjs/websocket/manager.js.map +1 -0
  156. package/dist/cjs/websocket/socket.io.js +79 -0
  157. package/dist/cjs/websocket/socket.io.js.map +1 -0
  158. package/dist/esm/auth.js +76 -0
  159. package/dist/esm/auth.js.map +1 -0
  160. package/{src → dist/esm}/cluster.js +9 -14
  161. package/dist/esm/cluster.js.map +1 -0
  162. package/dist/esm/index.js +3 -0
  163. package/dist/esm/index.js.map +1 -0
  164. package/dist/esm/middleware/404.js +11 -0
  165. package/dist/esm/middleware/404.js.map +1 -0
  166. package/dist/esm/middleware/cache.js +11 -0
  167. package/dist/esm/middleware/cache.js.map +1 -0
  168. package/dist/esm/middleware/connection.js +46 -0
  169. package/dist/esm/middleware/connection.js.map +1 -0
  170. package/dist/esm/middleware/context.js +17 -0
  171. package/dist/esm/middleware/context.js.map +1 -0
  172. package/dist/esm/middleware/cors.js +45 -0
  173. package/dist/esm/middleware/cors.js.map +1 -0
  174. package/dist/esm/middleware/swagger.js +14 -0
  175. package/dist/esm/middleware/swagger.js.map +1 -0
  176. package/dist/esm/middleware/user.js +45 -0
  177. package/dist/esm/middleware/user.js.map +1 -0
  178. package/{src → dist/esm}/oauth-providers/dropbox.js +11 -9
  179. package/dist/esm/oauth-providers/dropbox.js.map +1 -0
  180. package/{src → dist/esm}/oauth-providers/facebook.js +6 -9
  181. package/dist/esm/oauth-providers/facebook.js.map +1 -0
  182. package/{src → dist/esm}/oauth-providers/google.js +8 -11
  183. package/dist/esm/oauth-providers/google.js.map +1 -0
  184. package/dist/esm/oauth-providers/index.js +19 -0
  185. package/dist/esm/oauth-providers/index.js.map +1 -0
  186. package/{src → dist/esm}/oauth-providers/instagram.js +6 -9
  187. package/dist/esm/oauth-providers/instagram.js.map +1 -0
  188. package/dist/esm/oauth-providers/oauth-provider.js +2 -0
  189. package/dist/esm/oauth-providers/oauth-provider.js.map +1 -0
  190. package/{src → dist/esm}/oauth-providers/spotify.js +7 -10
  191. package/dist/esm/oauth-providers/spotify.js.map +1 -0
  192. package/dist/esm/package.json +3 -0
  193. package/dist/esm/routes/auth-change-password.js +70 -0
  194. package/dist/esm/routes/auth-change-password.js.map +1 -0
  195. package/dist/esm/routes/auth-delete.js +36 -0
  196. package/dist/esm/routes/auth-delete.js.map +1 -0
  197. package/dist/esm/routes/auth-forgot-password.js +61 -0
  198. package/dist/esm/routes/auth-forgot-password.js.map +1 -0
  199. package/dist/esm/routes/auth-reset-password.js +78 -0
  200. package/dist/esm/routes/auth-reset-password.js.map +1 -0
  201. package/dist/esm/routes/auth-signin.js +34 -0
  202. package/dist/esm/routes/auth-signin.js.map +1 -0
  203. package/dist/esm/routes/auth-signout.js +46 -0
  204. package/dist/esm/routes/auth-signout.js.map +1 -0
  205. package/dist/esm/routes/auth-signup.js +126 -0
  206. package/dist/esm/routes/auth-signup.js.map +1 -0
  207. package/dist/esm/routes/auth-state.js +13 -0
  208. package/dist/esm/routes/auth-state.js.map +1 -0
  209. package/dist/esm/routes/auth-update.js +115 -0
  210. package/dist/esm/routes/auth-update.js.map +1 -0
  211. package/dist/esm/routes/auth-verify-email.js +52 -0
  212. package/dist/esm/routes/auth-verify-email.js.map +1 -0
  213. package/dist/esm/routes/auth.js +51 -0
  214. package/dist/esm/routes/auth.js.map +1 -0
  215. package/dist/esm/routes/data-exists.js +21 -0
  216. package/dist/esm/routes/data-exists.js.map +1 -0
  217. package/dist/esm/routes/data-export.js +36 -0
  218. package/dist/esm/routes/data-export.js.map +1 -0
  219. package/dist/esm/routes/data-get.js +53 -0
  220. package/dist/esm/routes/data-get.js.map +1 -0
  221. package/dist/esm/routes/data-import.js +42 -0
  222. package/dist/esm/routes/data-import.js.map +1 -0
  223. package/dist/esm/routes/data-index-create.js +31 -0
  224. package/dist/esm/routes/data-index-create.js.map +1 -0
  225. package/dist/esm/routes/data-index-delete.js +23 -0
  226. package/dist/esm/routes/data-index-delete.js.map +1 -0
  227. package/dist/esm/routes/data-index-list.js +22 -0
  228. package/dist/esm/routes/data-index-list.js.map +1 -0
  229. package/dist/esm/routes/data-query.js +57 -0
  230. package/dist/esm/routes/data-query.js.map +1 -0
  231. package/dist/esm/routes/data-reflect.js +76 -0
  232. package/dist/esm/routes/data-reflect.js.map +1 -0
  233. package/dist/esm/routes/data-schema-get.js +26 -0
  234. package/dist/esm/routes/data-schema-get.js.map +1 -0
  235. package/dist/esm/routes/data-schema-set.js +20 -0
  236. package/dist/esm/routes/data-schema-set.js.map +1 -0
  237. package/dist/esm/routes/data-schema-test.js +32 -0
  238. package/dist/esm/routes/data-schema-test.js.map +1 -0
  239. package/dist/esm/routes/data-schemas-list.js +22 -0
  240. package/dist/esm/routes/data-schemas-list.js.map +1 -0
  241. package/dist/esm/routes/data-set.js +57 -0
  242. package/dist/esm/routes/data-set.js.map +1 -0
  243. package/dist/esm/routes/data-sync-changes.js +54 -0
  244. package/dist/esm/routes/data-sync-changes.js.map +1 -0
  245. package/dist/esm/routes/data-sync-mutations.js +54 -0
  246. package/dist/esm/routes/data-sync-mutations.js.map +1 -0
  247. package/dist/esm/routes/data-transaction.js +104 -0
  248. package/dist/esm/routes/data-transaction.js.map +1 -0
  249. package/dist/esm/routes/data-update.js +56 -0
  250. package/dist/esm/routes/data-update.js.map +1 -0
  251. package/dist/esm/routes/data.js +59 -0
  252. package/dist/esm/routes/data.js.map +1 -0
  253. package/dist/esm/routes/docs.js +244 -0
  254. package/dist/esm/routes/docs.js.map +1 -0
  255. package/dist/esm/routes/meta-info.js +66 -0
  256. package/dist/esm/routes/meta-info.js.map +1 -0
  257. package/dist/esm/routes/meta-ping.js +8 -0
  258. package/dist/esm/routes/meta-ping.js.map +1 -0
  259. package/dist/esm/routes/meta-stats.js +15 -0
  260. package/dist/esm/routes/meta-stats.js.map +1 -0
  261. package/dist/esm/routes/meta.js +13 -0
  262. package/dist/esm/routes/meta.js.map +1 -0
  263. package/dist/esm/routes/oauth2-init.js +39 -0
  264. package/dist/esm/routes/oauth2-init.js.map +1 -0
  265. package/dist/esm/routes/oauth2-refresh.js +30 -0
  266. package/dist/esm/routes/oauth2-refresh.js.map +1 -0
  267. package/dist/esm/routes/oauth2-signin.js +248 -0
  268. package/dist/esm/routes/oauth2-signin.js.map +1 -0
  269. package/dist/esm/routes/webmanager.js +23 -0
  270. package/dist/esm/routes/webmanager.js.map +1 -0
  271. package/dist/esm/rules.js +171 -0
  272. package/dist/esm/rules.js.map +1 -0
  273. package/dist/esm/schema/user.js +21 -0
  274. package/dist/esm/schema/user.js.map +1 -0
  275. package/dist/esm/server.js +344 -0
  276. package/dist/esm/server.js.map +1 -0
  277. package/dist/esm/settings/email.js +4 -0
  278. package/dist/esm/settings/email.js.map +1 -0
  279. package/dist/esm/settings/index.js +152 -0
  280. package/dist/esm/settings/index.js.map +1 -0
  281. package/dist/esm/shared/clients.js +23 -0
  282. package/dist/esm/shared/clients.js.map +1 -0
  283. package/dist/esm/shared/email.js +6 -0
  284. package/dist/esm/shared/email.js.map +1 -0
  285. package/dist/esm/shared/env.js +4 -0
  286. package/dist/esm/shared/env.js.map +1 -0
  287. package/dist/esm/shared/error.js +27 -0
  288. package/dist/esm/shared/error.js.map +1 -0
  289. package/dist/esm/shared/http.js +16 -0
  290. package/dist/esm/shared/http.js.map +1 -0
  291. package/dist/esm/shared/password.js +39 -0
  292. package/dist/esm/shared/password.js.map +1 -0
  293. package/dist/esm/shared/rootpath.js +12 -0
  294. package/dist/esm/shared/rootpath.js.map +1 -0
  295. package/dist/esm/shared/signin.js +125 -0
  296. package/dist/esm/shared/signin.js.map +1 -0
  297. package/{src/oauth-providers → dist/esm/shared}/simple-fetch.js +7 -10
  298. package/dist/esm/shared/simple-fetch.js.map +1 -0
  299. package/dist/esm/shared/tokens.js +72 -0
  300. package/dist/esm/shared/tokens.js.map +1 -0
  301. package/dist/esm/shared/validate.js +42 -0
  302. package/dist/esm/shared/validate.js.map +1 -0
  303. package/dist/esm/start.js +48 -0
  304. package/dist/esm/start.js.map +1 -0
  305. package/dist/esm/test.js +9 -0
  306. package/dist/esm/test.js.map +1 -0
  307. package/dist/esm/websocket/index.js +288 -0
  308. package/dist/esm/websocket/index.js.map +1 -0
  309. package/dist/esm/websocket/manager.js +12 -0
  310. package/dist/esm/websocket/manager.js.map +1 -0
  311. package/dist/esm/websocket/socket.io.js +73 -0
  312. package/dist/esm/websocket/socket.io.js.map +1 -0
  313. package/dist/types/auth.d.ts +3 -0
  314. package/dist/types/cluster.d.ts +1 -0
  315. package/dist/types/index.d.ts +2 -0
  316. package/dist/types/middleware/404.d.ts +7 -0
  317. package/dist/types/middleware/cache.d.ts +3 -0
  318. package/dist/types/middleware/connection.d.ts +7 -0
  319. package/dist/types/middleware/context.d.ts +3 -0
  320. package/dist/types/middleware/cors.d.ts +25 -0
  321. package/dist/types/middleware/swagger.d.ts +3 -0
  322. package/dist/types/middleware/user.d.ts +2 -0
  323. package/dist/types/oauth-providers/dropbox.d.ts +63 -0
  324. package/dist/types/oauth-providers/facebook.d.ts +45 -0
  325. package/dist/types/oauth-providers/google.d.ts +47 -0
  326. package/dist/types/oauth-providers/index.d.ts +18 -0
  327. package/dist/types/oauth-providers/instagram.d.ts +54 -0
  328. package/dist/types/oauth-providers/oauth-provider.d.ts +70 -0
  329. package/dist/types/oauth-providers/spotify.d.ts +57 -0
  330. package/dist/types/routes/auth-change-password.d.ts +20 -0
  331. package/dist/types/routes/auth-delete.d.ts +16 -0
  332. package/dist/types/routes/auth-forgot-password.d.ts +16 -0
  333. package/dist/types/routes/auth-reset-password.d.ts +23 -0
  334. package/dist/types/routes/auth-signin.d.ts +24 -0
  335. package/dist/types/routes/auth-signout.d.ts +14 -0
  336. package/dist/types/routes/auth-signup.d.ts +32 -0
  337. package/dist/types/routes/auth-state.d.ts +13 -0
  338. package/dist/types/routes/auth-update.d.ts +33 -0
  339. package/dist/types/routes/auth-verify-email.d.ts +21 -0
  340. package/dist/types/routes/auth.d.ts +6 -0
  341. package/dist/types/routes/data-exists.d.ts +9 -0
  342. package/dist/types/routes/data-export.d.ts +10 -0
  343. package/dist/types/routes/data-get.d.ts +14 -0
  344. package/dist/types/routes/data-import.d.ts +13 -0
  345. package/dist/types/routes/data-index-create.d.ts +51 -0
  346. package/dist/types/routes/data-index-delete.d.ts +17 -0
  347. package/dist/types/routes/data-index-list.d.ts +21 -0
  348. package/dist/types/routes/data-query.d.ts +49 -0
  349. package/dist/types/routes/data-reflect.d.ts +29 -0
  350. package/dist/types/routes/data-schema-get.d.ts +11 -0
  351. package/dist/types/routes/data-schema-set.d.ts +19 -0
  352. package/dist/types/routes/data-schema-test.d.ts +21 -0
  353. package/dist/types/routes/data-schemas-list.d.ts +11 -0
  354. package/dist/types/routes/data-set.d.ts +27 -0
  355. package/dist/types/routes/data-sync-changes.d.ts +28 -0
  356. package/dist/types/routes/data-sync-mutations.d.ts +28 -0
  357. package/dist/types/routes/data-transaction.d.ts +34 -0
  358. package/dist/types/routes/data-update.d.ts +27 -0
  359. package/dist/types/routes/data.d.ts +3 -0
  360. package/dist/types/routes/docs.d.ts +3 -0
  361. package/dist/types/routes/meta-info.d.ts +11 -0
  362. package/dist/types/routes/meta-ping.d.ts +7 -0
  363. package/dist/types/routes/meta-stats.d.ts +13 -0
  364. package/dist/types/routes/meta.d.ts +3 -0
  365. package/dist/types/routes/oauth2-init.d.ts +13 -0
  366. package/dist/types/routes/oauth2-refresh.d.ts +17 -0
  367. package/dist/types/routes/oauth2-signin.d.ts +15 -0
  368. package/dist/types/routes/webmanager.d.ts +3 -0
  369. package/dist/types/rules.d.ts +41 -0
  370. package/dist/types/schema/user.d.ts +85 -0
  371. package/dist/types/server.d.ts +106 -0
  372. package/dist/types/settings/email.d.ts +14 -0
  373. package/dist/types/settings/index.d.ts +165 -0
  374. package/dist/types/shared/clients.d.ts +44 -0
  375. package/dist/types/shared/email.d.ts +34 -0
  376. package/dist/types/shared/env.d.ts +42 -0
  377. package/dist/types/shared/error.d.ts +15 -0
  378. package/dist/types/shared/http.d.ts +14 -0
  379. package/dist/types/shared/password.d.ts +19 -0
  380. package/dist/types/shared/rootpath.d.ts +2 -0
  381. package/dist/types/shared/signin.d.ts +31 -0
  382. package/dist/types/shared/simple-fetch.d.ts +21 -0
  383. package/dist/types/shared/tokens.d.ts +23 -0
  384. package/dist/types/shared/validate.d.ts +22 -0
  385. package/dist/types/start.d.ts +1 -0
  386. package/dist/types/test.d.ts +1 -0
  387. package/dist/types/websocket/index.d.ts +2 -0
  388. package/dist/types/websocket/manager.d.ts +99 -0
  389. package/dist/types/websocket/socket.io.d.ts +10 -0
  390. package/package.json +25 -8
  391. package/src/auth.ts +87 -0
  392. package/src/cluster.ts +62 -0
  393. package/src/index.ts +2 -0
  394. package/src/middleware/404.ts +13 -0
  395. package/src/middleware/cache.ts +15 -0
  396. package/src/middleware/connection.ts +48 -0
  397. package/src/middleware/context.ts +23 -0
  398. package/src/middleware/cors.ts +49 -0
  399. package/src/middleware/swagger.ts +19 -0
  400. package/src/middleware/user.ts +51 -0
  401. package/src/{ts/oauth-providers → oauth-providers}/dropbox.ts +1 -1
  402. package/src/{ts/oauth-providers → oauth-providers}/facebook.ts +1 -1
  403. package/src/{ts/oauth-providers → oauth-providers}/google.ts +1 -1
  404. package/src/oauth-providers/index.ts +20 -0
  405. package/src/{ts/oauth-providers → oauth-providers}/instagram.ts +1 -1
  406. package/src/{ts/oauth-providers → oauth-providers}/oauth-provider.ts +0 -0
  407. package/src/{ts/oauth-providers → oauth-providers}/spotify.ts +1 -1
  408. package/src/routes/auth-change-password.ts +89 -0
  409. package/src/routes/auth-change-password.yaml +74 -0
  410. package/src/routes/auth-delete.ts +47 -0
  411. package/src/routes/auth-delete.yaml +78 -0
  412. package/src/routes/auth-forgot-password.ts +73 -0
  413. package/src/routes/auth-forgot-password.yaml +50 -0
  414. package/src/routes/auth-reset-password.ts +93 -0
  415. package/src/routes/auth-reset-password.yaml +54 -0
  416. package/src/routes/auth-signin.ts +55 -0
  417. package/src/routes/auth-signin.yaml +130 -0
  418. package/src/routes/auth-signout.ts +61 -0
  419. package/src/routes/auth-signout.yaml +46 -0
  420. package/src/routes/auth-signup.ts +161 -0
  421. package/src/routes/auth-signup.yaml +136 -0
  422. package/src/routes/auth-state.ts +20 -0
  423. package/src/routes/auth-state.yaml +29 -0
  424. package/src/routes/auth-update.ts +147 -0
  425. package/src/routes/auth-update.yaml +152 -0
  426. package/src/routes/auth-verify-email.ts +67 -0
  427. package/src/routes/auth-verify-email.yaml +53 -0
  428. package/src/routes/auth.ts +67 -0
  429. package/src/routes/data-exists.ts +31 -0
  430. package/src/routes/data-exists.yaml +44 -0
  431. package/src/routes/data-export.ts +51 -0
  432. package/src/routes/data-export.yaml +64 -0
  433. package/src/routes/data-get.ts +68 -0
  434. package/src/routes/data-get.yaml +54 -0
  435. package/src/routes/data-import.ts +56 -0
  436. package/src/routes/data-import.yaml +75 -0
  437. package/src/routes/data-index-create.ts +85 -0
  438. package/src/routes/data-index-create.yaml +105 -0
  439. package/src/routes/data-index-delete.ts +39 -0
  440. package/src/routes/data-index-delete.yaml +51 -0
  441. package/src/routes/data-index-list.ts +42 -0
  442. package/src/routes/data-index-list.yaml +80 -0
  443. package/src/routes/data-query.ts +97 -0
  444. package/src/routes/data-query.yaml +166 -0
  445. package/src/routes/data-reflect.ts +94 -0
  446. package/src/routes/data-reflect.yaml +124 -0
  447. package/src/routes/data-schema-get.ts +38 -0
  448. package/src/routes/data-schema-get.yaml +53 -0
  449. package/src/routes/data-schema-set.ts +38 -0
  450. package/src/routes/data-schema-set.yaml +60 -0
  451. package/src/routes/data-schema-test.ts +53 -0
  452. package/src/routes/data-schema-test.yaml +66 -0
  453. package/src/routes/data-schemas-list.ts +33 -0
  454. package/src/routes/data-schemas-list.yaml +41 -0
  455. package/src/routes/data-set.ts +76 -0
  456. package/src/routes/data-set.yaml +71 -0
  457. package/src/routes/data-sync-changes.ts +78 -0
  458. package/src/routes/data-sync-changes.yaml +67 -0
  459. package/src/routes/data-sync-mutations.ts +78 -0
  460. package/src/routes/data-sync-mutations.yaml +67 -0
  461. package/src/routes/data-transaction-finish.yaml +76 -0
  462. package/src/routes/data-transaction-start.yaml +58 -0
  463. package/src/routes/data-transaction.ts +144 -0
  464. package/src/routes/data-update.ts +77 -0
  465. package/src/routes/data-update.yaml +71 -0
  466. package/src/routes/data.ts +79 -0
  467. package/src/routes/docs.ts +249 -0
  468. package/src/routes/meta-info.ts +80 -0
  469. package/src/routes/meta-info.yaml +41 -0
  470. package/src/routes/meta-ping.ts +15 -0
  471. package/src/routes/meta-ping.yaml +23 -0
  472. package/src/routes/meta-stats.ts +31 -0
  473. package/src/routes/meta-stats.yaml +41 -0
  474. package/src/routes/meta.ts +18 -0
  475. package/src/routes/oauth2-init.ts +44 -0
  476. package/src/routes/oauth2-init.yaml +63 -0
  477. package/src/routes/oauth2-refresh.ts +39 -0
  478. package/src/routes/oauth2-refresh.yaml +65 -0
  479. package/src/routes/oauth2-signin.ts +281 -0
  480. package/src/routes/oauth2-signin.yaml +66 -0
  481. package/src/routes/webmanager.ts +29 -0
  482. package/src/rules.ts +196 -0
  483. package/src/schema/user.ts +99 -0
  484. package/src/server.ts +416 -0
  485. package/src/settings/email.ts +18 -0
  486. package/src/settings/index.ts +241 -0
  487. package/src/shared/clients.ts +31 -0
  488. package/src/shared/email.ts +33 -0
  489. package/src/shared/env.ts +38 -0
  490. package/src/shared/error.ts +37 -0
  491. package/src/shared/http.ts +24 -0
  492. package/src/shared/password.ts +41 -0
  493. package/src/shared/rootpath.ts +15 -0
  494. package/src/shared/signin.ts +143 -0
  495. package/src/{ts/oauth-providers → shared}/simple-fetch.ts +2 -2
  496. package/src/shared/tokens.ts +77 -0
  497. package/src/shared/validate.ts +53 -0
  498. package/src/{start.js → start.ts} +7 -5
  499. package/src/test.ts +10 -0
  500. package/src/websocket/index.ts +320 -0
  501. package/src/websocket/manager.ts +46 -0
  502. package/src/websocket/socket.io.ts +91 -0
  503. package/tsconfig-cjs.json +10 -0
  504. package/tsconfig.json +13 -5
  505. package/{src/webmanager → webmanager}/index.html +0 -0
  506. package/{src/webmanager → webmanager}/index.js +0 -0
  507. package/src/acebase-server.js +0 -3053
  508. package/src/index.d.ts +0 -212
  509. package/src/index.js +0 -2
@@ -0,0 +1,31 @@
1
+ import { EventSubscriptionCallback, IApiQuery, IApiQueryOptions } from "acebase-core/src/api";
2
+ import { DbUserAccountDetails } from "../schema/user";
3
+ import { HttpSocket } from "./http";
4
+
5
+ export class ConnectedClient {
6
+ readonly id: string;
7
+
8
+ /**
9
+ *
10
+ * @param socket Socket object used by the framework
11
+ * @param id optional: use if the socket object does not have an `id` property.
12
+ */
13
+ constructor (public socket: HttpSocket, id?: string) {
14
+ this.id = id ?? socket.id;
15
+ if (!this.id) { throw new Error('Socket has no id'); }
16
+ }
17
+ // get id() { return this.socket.id; };
18
+ readonly connectedDate: Date = new Date();
19
+
20
+ /** user details if this socket client is signed in */
21
+ user?: DbUserAccountDetails;
22
+
23
+ /** Active event subscriptions for this client */
24
+ subscriptions: { [path: string]: Array<{ path: string, event: string, callback: EventSubscriptionCallback }> } = {};
25
+
26
+ /** Active realtime query subscriptions for this client */
27
+ realtimeQueries: { [id: string]: { path: string; query: IApiQuery, options: IApiQueryOptions }} = {};
28
+
29
+ /** Currently running transactions */
30
+ transactions: { [id: string]: { id: string; started: number; path: string; context: any; finish?: (val?: any) => Promise<any>; timeout: NodeJS.Timeout } } = {};
31
+ }
@@ -0,0 +1,33 @@
1
+ export interface AceBaseEmailRequest {
2
+ /** email request type */
3
+ type: string;
4
+ };
5
+
6
+ export interface AceBaseUserEmailRequest extends AceBaseEmailRequest {
7
+ user: { uid: string; email: string; username?: string; displayName?: string; settings?: any };
8
+ ip: string;
9
+ date: Date
10
+ };
11
+
12
+ export interface AceBaseUserSignupEmailRequest extends AceBaseUserEmailRequest {
13
+ type: 'user_signup';
14
+ activationCode: string;
15
+ emailVerified: boolean;
16
+ provider: string;
17
+ };
18
+
19
+ export interface AceBaseUserSignInEmailRequest extends AceBaseUserEmailRequest {
20
+ type: 'user_signin';
21
+ activationCode: string;
22
+ emailVerified: boolean;
23
+ provider: string;
24
+ };
25
+
26
+ export interface AceBaseUserResetPasswordEmailRequest extends AceBaseUserEmailRequest {
27
+ type: 'user_reset_password';
28
+ resetCode: string;
29
+ }
30
+
31
+ export interface AceBaseUserResetPasswordSuccessEmailRequest extends AceBaseUserEmailRequest {
32
+ type: 'user_reset_password_success';
33
+ }
@@ -0,0 +1,38 @@
1
+ import type { HttpApp, Request } from './http';
2
+ import type { AceBase, DataReference } from 'acebase';
3
+ import type { AceBaseServerConfig } from '../settings';
4
+ import type { DbUserAccountDetails } from '../schema/user';
5
+ import type { ConnectedClient } from './clients';
6
+ import type { DebugLogger, SimpleCache } from 'acebase-core';
7
+ import type { IOAuth2Provider } from '../oauth-providers/oauth-provider';
8
+ import type { Server as HttpServer } from 'http';
9
+ import type { Server as SecureHttpServer } from 'https';
10
+ import type { PathBasedRules } from '../rules';
11
+ import { Api } from 'acebase-core/src/api';
12
+
13
+ export interface RouteInitEnvironment {
14
+ server: HttpServer | SecureHttpServer;
15
+ app: HttpApp;
16
+ config: AceBaseServerConfig;
17
+ db: AceBase & { api: Api };
18
+ authDb: AceBase;
19
+ debug: DebugLogger;
20
+ securityRef: DataReference;
21
+ authRef: DataReference;
22
+ logRef: DataReference;
23
+ tokenSalt: string;
24
+ clients: Map<string, ConnectedClient>;
25
+ authCache: SimpleCache<string, DbUserAccountDetails>;
26
+ authProviders: { [providerName: string]: IOAuth2Provider };
27
+ rules: PathBasedRules
28
+ };
29
+
30
+ export interface RouteRequestEnvironment {
31
+ /** If the request has an Authentication: bearer token, the user will be bound to the incoming request */
32
+ user?: DbUserAccountDetails;
33
+
34
+ /** If context is sent through AceBase-Context header, it will be bound to the incoming request */
35
+ context?: { [key: string]: any };
36
+ };
37
+
38
+ export type RouteRequest<Params = any, ResBody = any, ReqBody = any, ReqQuery = any, Locals extends Record<string, any> = Record<string, any>> = Request<Params, ResBody, ReqBody, ReqQuery, Locals> & RouteRequestEnvironment;
@@ -0,0 +1,37 @@
1
+ import { Response } from './http';
2
+
3
+ export const sendNotAuthenticatedError = (res: Response, code: string, message: string) => {
4
+ res.statusCode = 401; // Unauthorized (not unauthenticated)
5
+ res.statusMessage = 'Not Authenticated';
6
+ res.contentType('application/json').send({ code, message });
7
+ };
8
+
9
+ export const sendUnauthorizedError = (res: Response, code: string, message: string) => {
10
+ res.statusCode = 403; // Forbidden
11
+ res.statusMessage = 'Unauthorized';
12
+ res.contentType('application/json').send({ code, message });
13
+ };
14
+
15
+ interface ErrorLike {
16
+ code?: string;
17
+ message: string;
18
+ stack?: string;
19
+ };
20
+
21
+ export const sendError = (res: Response, err: ErrorLike) => {
22
+ res.contentType('application/json');
23
+ if (typeof err.code === 'string') {
24
+ sendBadRequestError(res, err as { code: string; message: string }); //res.status(400).send({ code: err.code, message: err.message }); // Bad Request
25
+ }
26
+ else {
27
+ sendUnexpectedError(res, err as Error); // res.status(500).send({ code: 'unknown', message: 'server error', details: err.message }); // Internal server error
28
+ }
29
+ }
30
+
31
+ export const sendBadRequestError = (res: Response, err: { code: string, message: string }) => {
32
+ res.status(400).contentType('application/json').send({ code: err.code, message: err.message }); // Bad Request
33
+ }
34
+
35
+ export const sendUnexpectedError = (res: Response, err: Error) => {
36
+ res.status(500).contentType('application/json').send({ code: 'unexpected', message: 'server error', details: err.message }); // Internal server error
37
+ }
@@ -0,0 +1,24 @@
1
+ import type { Socket } from 'socket.io';
2
+ export type { Express, Request, Response } from 'express';
3
+ import * as express from 'express';
4
+ const createExpress = (express as any).default ?? express; // ESM and CJS compatible approach
5
+
6
+ export type HttpApp = express.Express;
7
+ export type HttpSocket = Socket;
8
+
9
+ /**
10
+ * Creates an app that handles http requests, adds json body parsing.
11
+ * @param settings
12
+ * @returns
13
+ */
14
+ export const createApp = (settings: { trustProxy: boolean; maxPayloadSize: string }) => {
15
+ const app = createExpress();
16
+
17
+ // When behind a trusted proxy server, req.ip and req.hostname will be set the right way
18
+ app.set('trust proxy', settings.trustProxy);
19
+
20
+ // Parse json request bodies
21
+ app.use(express.json({ limit: settings.maxPayloadSize })); // , extended: true ?
22
+
23
+ return app as HttpApp;
24
+ }
@@ -0,0 +1,41 @@
1
+ import * as crypto from 'crypto';
2
+
3
+ export const generatePassword = () => {
4
+ return Array.prototype.reduce.call('abcedefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ012345789!@#$%&', (password, c, i, chars) => {
5
+ if (i > 15) { return password; }
6
+ return password + chars[Math.floor(Math.random() * chars.length)];
7
+ }, '');
8
+ };
9
+
10
+ /**
11
+ * Generates a random salt and hashes the provided password with it. The resulting salt and hash should be stored in the database
12
+ * @param password password to hash
13
+ */
14
+ export const createPasswordHash = (password: string) => {
15
+ let length = 16;
16
+ let salt = crypto.randomBytes(Math.ceil(length/2)).toString('hex').slice(0,length);
17
+ let hash = crypto.createHmac('sha512', salt).update(password).digest('hex');
18
+ return {
19
+ salt,
20
+ hash
21
+ }
22
+ };
23
+
24
+ /**
25
+ * For checking passwords: uses given password and salt to get the hash that can be compared to a stored version.
26
+ * @param password A password prodived by the user trying to sign in
27
+ * @param salt the salt used to generate the hash, must be stored with the hash in the database
28
+ */
29
+ export const getPasswordHash = (password: string, salt: string) => {
30
+ return crypto.createHmac('sha512', salt).update(password).digest('hex');
31
+ };
32
+
33
+ /**
34
+ * Backward compatibility with old saltless md5 passwords. Becomes obsolete once all passwords have been updated (probably already so)
35
+ */
36
+ export const getOldPasswordHash = (password: string) => {
37
+ // Backward compatibility with old saltless md5 passwords.
38
+ // Becomes obsolete once all passwords have been updated
39
+ return crypto.createHash('md5').update(password).digest('hex');
40
+ };
41
+
@@ -0,0 +1,15 @@
1
+ import { resolve } from "path";
2
+
3
+ // This file is in ./src/shared/rootpath.ts
4
+ // When this code runs it is at ./dist/cjs/shared/rootpath.js or ./dist/esm/shared/rootpath.js
5
+ // So, the package root is at ../../..
6
+ let currentDir = __dirname;
7
+
8
+ if (process.platform === 'win32' && currentDir.startsWith('/')) {
9
+ // tsc-esm-fix does not handle win32 file urls correctly, the drive letter in import.meta.url is prefixed with a slash: file:///C:/dir/file.js
10
+ currentDir = currentDir.slice(1);
11
+ }
12
+
13
+ export const packageRootPath = resolve(currentDir, '../../..');
14
+
15
+ export default packageRootPath;
@@ -0,0 +1,143 @@
1
+ import { ID } from "acebase-core";
2
+ import { DbUserAccountDetails } from "../schema/user";
3
+ import { RouteInitEnvironment, RouteRequest } from "./env";
4
+ import { createPasswordHash, getOldPasswordHash, getPasswordHash } from "./password";
5
+ import { decodePublicAccessToken } from "./tokens";
6
+
7
+ export type SignInCredentials =
8
+ { method: 'token'; access_token: string } |
9
+ { method: 'private_token'; access_token: string } |
10
+ { method: 'email'; email: string; password: string } |
11
+ { method: 'account', username: string, password: string };
12
+
13
+ export class SignInError extends Error {
14
+ constructor(public code: string, message: string, public details: Object = {}) {
15
+ super(message);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Signs in a user and logs the request. If successful, adds the user to authCache, binds the user to the http request and returns the user details.
21
+ * Throws a `SignInError` if sign in fails for a known reason.
22
+ * @param credentials credentials to sign in the user with
23
+ * @param env environment state
24
+ * @param req current http request
25
+ * @returns
26
+ */
27
+ export const signIn = async (credentials: SignInCredentials, env: RouteInitEnvironment, req: RouteRequest) => {
28
+ try {
29
+ const query = env.authRef.query();
30
+ let tokenDetails: ReturnType<typeof decodePublicAccessToken>;
31
+ switch (credentials.method) {
32
+ case 'token': {
33
+ if (typeof credentials.access_token !== 'string') {
34
+ throw new SignInError('invalid_details', 'sign in request has invalid arguments');
35
+ }
36
+ try {
37
+ tokenDetails = decodePublicAccessToken(credentials.access_token, env.tokenSalt);
38
+ query.filter('access_token', '==', tokenDetails.access_token);
39
+ }
40
+ catch (err) {
41
+ throw new SignInError('invalid_token', err.message);
42
+ }
43
+ break;
44
+ }
45
+ case 'private_token': {
46
+ // Method used internally: uses the access token extracted from a public access token (see tokenDetails.access_token in above 'token' case)
47
+ if (typeof credentials.access_token !== 'string') {
48
+ throw new SignInError('invalid_details', 'sign in request has invalid arguments');
49
+ }
50
+ query.filter('access_token', '==', credentials.access_token);
51
+ break;
52
+ }
53
+ case 'email': {
54
+ if (typeof credentials.email !== 'string' || typeof credentials.password !== 'string') {
55
+ throw new SignInError('invalid_details', 'sign in request has invalid arguments');
56
+ }
57
+ query.filter('email', '==', credentials.email);
58
+ break;
59
+ }
60
+ case 'account': {
61
+ if (typeof credentials.username !== 'string' || typeof credentials.password !== 'string') {
62
+ throw new SignInError('invalid_details', 'sign in request has invalid arguments');
63
+ }
64
+ query.filter('username', '==', credentials.username);
65
+ break;
66
+ }
67
+ default: {
68
+ throw new SignInError('invalid_method', `Unsupported sign in method ${(credentials as any).method}`);
69
+ }
70
+ }
71
+
72
+ const snaps = await query.get();
73
+ if (snaps.length === 0) {
74
+ throw new SignInError('not_found', `account not found`);
75
+ }
76
+ else if (snaps.length > 1) {
77
+ throw new SignInError('duplicate', `${snaps.length} users found with the same ${credentials.method}. Contact your database administrator`, { count: snaps.length });
78
+ }
79
+
80
+ const snap = snaps[0];
81
+ const user: DbUserAccountDetails = snap.val();
82
+ user.uid = snap.key as string;
83
+
84
+ if (user.is_disabled === true) {
85
+ throw new SignInError('account_disabled', 'Your account has been disabled. Contact your database administrator');
86
+ }
87
+ if (credentials.method === 'token' && tokenDetails.uid !== user.uid) {
88
+ throw new SignInError('token_mismatch', 'Sign in again');
89
+ }
90
+ if (credentials.method === 'account' || credentials.method === 'email') {
91
+ // Check password
92
+ let hash = user.password_salt ? getPasswordHash(credentials.password, user.password_salt) : getOldPasswordHash(credentials.password);
93
+ if (user.password !== hash) {
94
+ throw new SignInError('wrong_password', 'Incorrect password');
95
+ }
96
+ }
97
+
98
+ // Keep track of properties to update, both in db and in our object
99
+ const updates: Partial<DbUserAccountDetails> = {
100
+ // Update prev / last sign in stats
101
+ prev_signin: user.last_signin,
102
+ prev_signin_ip: user.last_signin_ip,
103
+ last_signin: new Date(),
104
+ last_signin_ip: req.ip
105
+ };
106
+
107
+ if ('password' in credentials) {
108
+ if (!user.password_salt) {
109
+ // OLD md5 password hash, convert to new salted hash
110
+ let pwd = createPasswordHash(credentials.password);
111
+ updates.password = pwd.hash;
112
+ updates.password_salt = pwd.salt;
113
+ }
114
+ if (!user.access_token) {
115
+ // Generate access token
116
+ updates.access_token = ID.generate();
117
+ updates.access_token_created = new Date();
118
+ }
119
+ }
120
+
121
+ // Update user object
122
+ Object.assign(user, updates);
123
+
124
+ // Update db
125
+ await snap.ref.update(updates);
126
+
127
+ // Log history item
128
+ env.logRef.push({ action: `signin`, type: credentials.method, [credentials.method]: credentials[credentials.method], ip: req.ip, date: new Date(), success: true });
129
+
130
+ // Add to cache
131
+ env.authCache.set(user.uid, user);
132
+
133
+ // Bind user to current request
134
+ req.user = user;
135
+
136
+ return user;
137
+ }
138
+ catch (err) {
139
+ // Log error
140
+ env.logRef.push({ action: 'signin', type: credentials.method, [credentials.method]: credentials[credentials.method], success: false, code: err.code || 'unexpected', message: err.code ? null : err.message, ip: req.ip, date: new Date(), ...err.details });
141
+ throw err;
142
+ }
143
+ }
@@ -1,4 +1,4 @@
1
- import * as https from 'https';
1
+ import { request } from 'https';
2
2
  export interface SimpleFetchResponse {
3
3
  readonly status: number;
4
4
  readonly headers: { get(name: string): string }
@@ -15,7 +15,7 @@ export function fetch(url: string, options?: { method?: 'GET'|'POST'|'PUT'|'DELE
15
15
  return new Promise((resolve, reject) => {
16
16
  const method = options?.method || 'GET';
17
17
  const headers = options?.headers;
18
- const req = https.request(url, { method, headers }, res => {
18
+ const req = request(url, { method, headers }, res => {
19
19
 
20
20
  // res.setEncoding('binary'); // will result in strings!!!!
21
21
  const ready = new Promise<Buffer>((resolve, reject) => {
@@ -0,0 +1,77 @@
1
+ import * as crypto from 'crypto';
2
+
3
+ export const createPublicAccessToken = (uid: string, ip: string, dbToken: string, password: string) => {
4
+ let obj = {
5
+ t: dbToken,
6
+ c: Date.now(),
7
+ u: uid,
8
+ i: ip
9
+ };
10
+ // let str = JSON.stringify(obj);
11
+ // str = Buffer.from(str).toString('base64');
12
+ // return 'a' + str; // version a
13
+ return 'b' + createSignedPublicToken(obj, password);
14
+ };
15
+
16
+ export const decodePublicAccessToken = (accessToken: string, password: string) : { access_token: string; uid: string; created: number; ip: string } => {
17
+ if (accessToken[0] === 'b') {
18
+ // New signed version
19
+ const obj = parseSignedPublicToken(accessToken.slice(1), password);
20
+ const details = {
21
+ access_token: obj.t,
22
+ uid: obj.u,
23
+ created: obj.c,
24
+ ip: obj.i
25
+ }
26
+ if (!details.access_token || !details.uid || !details.created || !details.ip) {
27
+ throw new Error('Invalid token');
28
+ }
29
+ return details;
30
+ }
31
+ else if (accessToken[0] === 'a') {
32
+ // Old insecure version, previously allowed until August 1, 2020.
33
+ throw new Error('Old token version not allowed');
34
+ }
35
+ }
36
+
37
+
38
+ const getSignature = (content, salt) => {
39
+ // Use fast md5 with salt to sign with. Large salt recommended!!
40
+ return crypto.createHash('md5').update(salt + content).digest('hex');
41
+ }
42
+
43
+ /**
44
+ * Sign objects with an md5 hash. An attacker might base4 decode it and see the content and generated checksum hash,
45
+ * but will need to guess the password used to generate the hash to manipulate it. This is not impossible but will take
46
+ * a very long time when using a large password
47
+ * @param obj data object to sign
48
+ * @param password password to use as salt for the generated md5 hash
49
+ * @returns base64 encoded signed token
50
+ */
51
+ export const createSignedPublicToken = (obj: any, password: string) => {
52
+ const str = JSON.stringify(obj);
53
+ const checksum = getSignature(str, password);
54
+ return Buffer.from(JSON.stringify({ v: 1, cs: checksum, d: str })).toString('base64');
55
+ };
56
+
57
+ /**
58
+ * Parses and validates a signed token that was previouslt generated by `createSignedPublicToken`
59
+ * @param str token previously generated by `createSignedPublicToken`
60
+ * @param password the same password used to create the token with
61
+ * @returns the original data object
62
+ */
63
+ export const parseSignedPublicToken = (str: string, password: string) => {
64
+ const json = Buffer.from(str, 'base64').toString('utf8');
65
+ const obj = JSON.parse(json) as { v: number; cs: string; d: string };
66
+ if (obj.v !== 1) {
67
+ throw new Error(`Unsupported version`);
68
+ }
69
+ if (typeof obj.cs !== 'string' || typeof obj.d !== 'string') {
70
+ throw new Error('Invalid token');
71
+ }
72
+ const checksum = obj.cs;
73
+ if (checksum !== getSignature(obj.d, password)) {
74
+ throw new Error(`compromised object`);
75
+ }
76
+ return JSON.parse(obj.d);
77
+ };
@@ -0,0 +1,53 @@
1
+ import { DataReference } from "acebase-core";
2
+
3
+ export const isValidEmail = (email: string): boolean => {
4
+ return /[a-z0-9_.+]+@([a-z0-9\-]+\.)+[a-z]{2,}/i.test(email);
5
+ };
6
+
7
+ export const isValidNewEmailAddress = async (authRef: DataReference, email: string): Promise<boolean> => {
8
+ const exists = await authRef.query().filter('email', '==', email).exists();
9
+ return !exists;
10
+ };
11
+
12
+ export const isValidNewUsername = async (authRef: DataReference, username): Promise<boolean> => {
13
+ const exists = await authRef.query().filter('username', '==', username).exists();
14
+ return !exists;
15
+ };
16
+
17
+ export const isValidUsername = (username: string): boolean => {
18
+ return username !== 'admin' && typeof username === 'string' && username.length >= 5 && /^[a-z0-9]+$/.test(username);
19
+ };
20
+
21
+ export const isValidDisplayName = (displayName: string): boolean => {
22
+ return typeof displayName === 'string' && displayName.length >= 5;
23
+ };
24
+
25
+ export const isValidPassword = (password: string): boolean => {
26
+ // return typeof password === 'string' && password.length >= 8 && password.indexOf(' ') < 0 && /[0-9]/.test(password) && /[a-z]/.test(password) && /[A-Z]/.test(password);
27
+ return typeof password === 'string' && password.length >= 8 && password.indexOf(' ') < 0; // Let client application set their own password rules. Keep minimum length of 8 and no spaces requirement.
28
+ };
29
+
30
+ export const isValidPicture = (picture: any): boolean => {
31
+ return picture === null || (typeof picture === 'object' && typeof picture.url === 'string' && typeof picture.width === 'number' && typeof picture.height === 'number');
32
+ };
33
+
34
+ export const isValidSettings = (settings: any): boolean => {
35
+ return typeof settings === 'undefined'
36
+ || (
37
+ typeof settings === 'object'
38
+ && Object.keys(settings).length <= 100 // max 100 settings
39
+ && Object.keys(settings).map(key => typeof settings[key]).every(t => ['string','number','boolean'].indexOf(t) >= 0) // only string, number, boolean values
40
+ && Object.keys(settings).filter(key => typeof settings[key] === 'string').every(key => settings[key].length <= 250) // strings values <= 250 chars
41
+ );
42
+ };
43
+
44
+ export type ValidationError<Code> = { code: Code, message: string };
45
+ export const invalidEmailError: ValidationError<'invalid_email'> = { code: 'invalid_email', message: 'Invalid email address' };
46
+ export const invalidUsernameError: ValidationError<'invalid_username'> = { code: 'invalid_username', message: 'Invalid username, must be at least 5 characters and can only contain lowercase characters a-z and 0-9' };
47
+ export const emailExistsError: ValidationError<'email_conflict'> = { code: 'email_conflict', message: 'Account with email address exists already' };
48
+ export const usernameExistsError: ValidationError<'username_conflict'> = { code: 'username_conflict', message: 'Account with username exists already' };
49
+ export const emailOrUsernameExistsError: ValidationError<'conflict'> = { code: 'conflict', message: `Account with username and/or email already exists` };
50
+ export const invalidDisplayNameError: ValidationError<'invalid_display_name'> = { code: 'invalid_display_name', message: 'Invalid display_name, must be at least 5 characters' };
51
+ export const invalidPasswordError: ValidationError<'invalid_password'> = { code: 'invalid_password', message: 'Invalid password, must be at least 8 characters and cannot contain spaces' };
52
+ export const invalidPictureError: ValidationError<'invalid_picture'> = { code: 'invalid_picture', message: 'Invalid picture, must be an object with url, width and height properties'};
53
+ export const invalidSettingsError: ValidationError<'invalid_settings'> = { code: 'invalid_settings', message: 'Invalid settings, must be an object and contain only string, number and/or boolean values. Additionaly, string values can have a maximum length of 250, and a maximum of 100 settings can be added' };
@@ -1,7 +1,8 @@
1
- const { AceBaseServer } = require('./acebase-server');
1
+ import { AceBaseServer } from './server';
2
+ import { AceBaseServerSettings } from './settings';
2
3
 
3
4
  // If one executes "node start.js [dbname=name] [host=ip] [port=nr]"
4
- function getVariable(name, defaultValue) {
5
+ function getVariable(name: string, defaultValue?: any) {
5
6
  // Checks if an argument with the name was passed,
6
7
  // or if an environment variable was set with that name,
7
8
  // else it will return the default value
@@ -10,14 +11,14 @@ function getVariable(name, defaultValue) {
10
11
  if (arg) { return arg.split('=')[1]; }
11
12
  if (typeof process.env[name] !== 'undefined') { return process.env[name]; }
12
13
  return defaultValue;
13
- }
14
+ };
14
15
 
15
16
  const path = getVariable('DBPATH', '.');
16
17
  const dbname = getVariable('DBNAME', 'default');
17
- const host = getVariable('HOST', '0.0.0.0');
18
+ const host = getVariable('HOST', 'localhost'); // '0.0.0.0'
18
19
  const port = +getVariable('PORT', 3000);
19
20
  const ipcPort = +getVariable('IPC_PORT', 0);
20
- const options = { host, port, path };
21
+ const options: AceBaseServerSettings = { host, port, path };
21
22
  if (ipcPort > 0) {
22
23
  const role = getVariable('IPC_ROLE');
23
24
  if (!['master','worker'].includes(role)) {
@@ -40,4 +41,5 @@ if (+getVariable('TXLOG', 0) === 1) {
40
41
  const server = new AceBaseServer(dbname, options);
41
42
  server.once("ready", () => {
42
43
  server.debug.log(`AceBase server running`);
44
+ process.send?.('ready'); // When using pm2, you can use --wait-ready flag (see https://pm2.keymetrics.io/docs/usage/signals-clean-restart/)
43
45
  });
package/src/test.ts ADDED
@@ -0,0 +1,10 @@
1
+ // Starts a test server for debugging sessions
2
+ import { AceBaseServer } from './server';
3
+
4
+ // Make sure development environment is set
5
+ process.env.NODE_ENV = 'development';
6
+
7
+ const server = new AceBaseServer('default', { logLevel: 'verbose', host: 'localhost', port: 3000, path: '.' });
8
+ server.once('ready', () => {
9
+ console.log(`Ready to debug!`);
10
+ });