acebase-server 1.9.1 → 1.11.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 (512) hide show
  1. package/create-package-files +12 -0
  2. package/dist/cjs/auth.js +89 -0
  3. package/dist/cjs/auth.js.map +1 -0
  4. package/dist/cjs/cluster.js +57 -0
  5. package/dist/cjs/cluster.js.map +1 -0
  6. package/dist/cjs/index.js +25 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/cjs/middleware/404.js +15 -0
  9. package/dist/cjs/middleware/404.js.map +1 -0
  10. package/dist/cjs/middleware/cache.js +15 -0
  11. package/dist/cjs/middleware/cache.js.map +1 -0
  12. package/dist/cjs/middleware/connection.js +50 -0
  13. package/dist/cjs/middleware/connection.js.map +1 -0
  14. package/dist/cjs/middleware/context.js +21 -0
  15. package/dist/cjs/middleware/context.js.map +1 -0
  16. package/dist/cjs/middleware/cors.js +51 -0
  17. package/dist/cjs/middleware/cors.js.map +1 -0
  18. package/dist/cjs/middleware/swagger.js +18 -0
  19. package/dist/cjs/middleware/swagger.js.map +1 -0
  20. package/dist/cjs/middleware/user.js +58 -0
  21. package/dist/cjs/middleware/user.js.map +1 -0
  22. package/dist/cjs/oauth-providers/dropbox.js +110 -0
  23. package/dist/cjs/oauth-providers/dropbox.js.map +1 -0
  24. package/dist/cjs/oauth-providers/facebook.js +86 -0
  25. package/dist/cjs/oauth-providers/facebook.js.map +1 -0
  26. package/dist/cjs/oauth-providers/google.js +126 -0
  27. package/dist/cjs/oauth-providers/google.js.map +1 -0
  28. package/dist/cjs/oauth-providers/index.js +27 -0
  29. package/dist/cjs/oauth-providers/index.js.map +1 -0
  30. package/dist/cjs/oauth-providers/instagram.js +81 -0
  31. package/dist/cjs/oauth-providers/instagram.js.map +1 -0
  32. package/dist/cjs/oauth-providers/oauth-provider.js +26 -0
  33. package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -0
  34. package/dist/cjs/oauth-providers/spotify.js +114 -0
  35. package/dist/cjs/oauth-providers/spotify.js.map +1 -0
  36. package/dist/cjs/package.json +3 -0
  37. package/dist/cjs/routes/auth-change-password.js +85 -0
  38. package/dist/cjs/routes/auth-change-password.js.map +1 -0
  39. package/dist/cjs/routes/auth-delete.js +51 -0
  40. package/dist/cjs/routes/auth-delete.js.map +1 -0
  41. package/dist/cjs/routes/auth-forgot-password.js +75 -0
  42. package/dist/cjs/routes/auth-forgot-password.js.map +1 -0
  43. package/dist/cjs/routes/auth-reset-password.js +94 -0
  44. package/dist/cjs/routes/auth-reset-password.js.map +1 -0
  45. package/dist/cjs/routes/auth-signin.js +47 -0
  46. package/dist/cjs/routes/auth-signin.js.map +1 -0
  47. package/dist/cjs/routes/auth-signout.js +60 -0
  48. package/dist/cjs/routes/auth-signout.js.map +1 -0
  49. package/dist/cjs/routes/auth-signup.js +141 -0
  50. package/dist/cjs/routes/auth-signup.js.map +1 -0
  51. package/dist/cjs/routes/auth-state.js +26 -0
  52. package/dist/cjs/routes/auth-state.js.map +1 -0
  53. package/dist/cjs/routes/auth-update.js +129 -0
  54. package/dist/cjs/routes/auth-update.js.map +1 -0
  55. package/dist/cjs/routes/auth-verify-email.js +67 -0
  56. package/dist/cjs/routes/auth-verify-email.js.map +1 -0
  57. package/dist/cjs/routes/auth.js +55 -0
  58. package/dist/cjs/routes/auth.js.map +1 -0
  59. package/dist/cjs/routes/data-exists.js +34 -0
  60. package/dist/cjs/routes/data-exists.js.map +1 -0
  61. package/dist/cjs/routes/data-export.js +49 -0
  62. package/dist/cjs/routes/data-export.js.map +1 -0
  63. package/dist/cjs/routes/data-get.js +67 -0
  64. package/dist/cjs/routes/data-get.js.map +1 -0
  65. package/dist/cjs/routes/data-import.js +55 -0
  66. package/dist/cjs/routes/data-import.js.map +1 -0
  67. package/dist/cjs/routes/data-index-create.js +45 -0
  68. package/dist/cjs/routes/data-index-create.js.map +1 -0
  69. package/dist/cjs/routes/data-index-delete.js +36 -0
  70. package/dist/cjs/routes/data-index-delete.js.map +1 -0
  71. package/dist/cjs/routes/data-index-list.js +35 -0
  72. package/dist/cjs/routes/data-index-list.js.map +1 -0
  73. package/dist/cjs/routes/data-query.js +71 -0
  74. package/dist/cjs/routes/data-query.js.map +1 -0
  75. package/dist/cjs/routes/data-reflect.js +89 -0
  76. package/dist/cjs/routes/data-reflect.js.map +1 -0
  77. package/dist/cjs/routes/data-schema-get.js +39 -0
  78. package/dist/cjs/routes/data-schema-get.js.map +1 -0
  79. package/dist/cjs/routes/data-schema-set.js +33 -0
  80. package/dist/cjs/routes/data-schema-set.js.map +1 -0
  81. package/dist/cjs/routes/data-schema-test.js +46 -0
  82. package/dist/cjs/routes/data-schema-test.js.map +1 -0
  83. package/dist/cjs/routes/data-schemas-list.js +35 -0
  84. package/dist/cjs/routes/data-schemas-list.js.map +1 -0
  85. package/dist/cjs/routes/data-set.js +75 -0
  86. package/dist/cjs/routes/data-set.js.map +1 -0
  87. package/dist/cjs/routes/data-sync-changes.js +68 -0
  88. package/dist/cjs/routes/data-sync-changes.js.map +1 -0
  89. package/dist/cjs/routes/data-sync-mutations.js +68 -0
  90. package/dist/cjs/routes/data-sync-mutations.js.map +1 -0
  91. package/dist/cjs/routes/data-transaction.js +133 -0
  92. package/dist/cjs/routes/data-transaction.js.map +1 -0
  93. package/dist/cjs/routes/data-update.js +74 -0
  94. package/dist/cjs/routes/data-update.js.map +1 -0
  95. package/dist/cjs/routes/data.js +63 -0
  96. package/dist/cjs/routes/data.js.map +1 -0
  97. package/dist/cjs/routes/docs.js +249 -0
  98. package/dist/cjs/routes/docs.js.map +1 -0
  99. package/dist/cjs/routes/meta-info.js +70 -0
  100. package/dist/cjs/routes/meta-info.js.map +1 -0
  101. package/dist/cjs/routes/meta-ping.js +12 -0
  102. package/dist/cjs/routes/meta-ping.js.map +1 -0
  103. package/dist/cjs/routes/meta-stats.js +28 -0
  104. package/dist/cjs/routes/meta-stats.js.map +1 -0
  105. package/dist/cjs/routes/meta.js +17 -0
  106. package/dist/cjs/routes/meta.js.map +1 -0
  107. package/dist/cjs/routes/oauth2-init.js +52 -0
  108. package/dist/cjs/routes/oauth2-init.js.map +1 -0
  109. package/dist/cjs/routes/oauth2-refresh.js +43 -0
  110. package/dist/cjs/routes/oauth2-refresh.js.map +1 -0
  111. package/dist/cjs/routes/oauth2-signin.js +263 -0
  112. package/dist/cjs/routes/oauth2-signin.js.map +1 -0
  113. package/dist/cjs/routes/webmanager.js +27 -0
  114. package/dist/cjs/routes/webmanager.js.map +1 -0
  115. package/dist/cjs/rules.js +175 -0
  116. package/dist/cjs/rules.js.map +1 -0
  117. package/dist/cjs/schema/user.js +26 -0
  118. package/dist/cjs/schema/user.js.map +1 -0
  119. package/dist/cjs/server.js +363 -0
  120. package/dist/cjs/server.js.map +1 -0
  121. package/dist/cjs/settings/email.js +5 -0
  122. package/dist/cjs/settings/email.js.map +1 -0
  123. package/dist/cjs/settings/index.js +158 -0
  124. package/dist/cjs/settings/index.js.map +1 -0
  125. package/dist/cjs/shared/clients.js +27 -0
  126. package/dist/cjs/shared/clients.js.map +1 -0
  127. package/dist/cjs/shared/email.js +7 -0
  128. package/dist/cjs/shared/email.js.map +1 -0
  129. package/{src/oauth-providers/oauth-provider.js → dist/cjs/shared/env.js} +3 -0
  130. package/dist/cjs/shared/env.js.map +1 -0
  131. package/dist/cjs/shared/error.js +35 -0
  132. package/dist/cjs/shared/error.js.map +1 -0
  133. package/dist/cjs/shared/http.js +21 -0
  134. package/dist/cjs/shared/http.js.map +1 -0
  135. package/dist/cjs/shared/password.js +46 -0
  136. package/dist/cjs/shared/password.js.map +1 -0
  137. package/dist/cjs/shared/rootpath.js +15 -0
  138. package/dist/cjs/shared/rootpath.js.map +1 -0
  139. package/dist/cjs/shared/signin.js +139 -0
  140. package/dist/cjs/shared/signin.js.map +1 -0
  141. package/dist/cjs/shared/simple-fetch.js +77 -0
  142. package/dist/cjs/shared/simple-fetch.js.map +1 -0
  143. package/dist/cjs/shared/tokens.js +79 -0
  144. package/dist/cjs/shared/tokens.js.map +1 -0
  145. package/dist/cjs/shared/validate.js +62 -0
  146. package/dist/cjs/shared/validate.js.map +1 -0
  147. package/dist/cjs/start.js +51 -0
  148. package/dist/cjs/start.js.map +1 -0
  149. package/dist/cjs/test.js +11 -0
  150. package/dist/cjs/test.js.map +1 -0
  151. package/dist/cjs/websocket/index.js +301 -0
  152. package/dist/cjs/websocket/index.js.map +1 -0
  153. package/dist/cjs/websocket/manager.js +16 -0
  154. package/dist/cjs/websocket/manager.js.map +1 -0
  155. package/dist/cjs/websocket/socket.io.js +76 -0
  156. package/dist/cjs/websocket/socket.io.js.map +1 -0
  157. package/dist/esm/auth.js +76 -0
  158. package/dist/esm/auth.js.map +1 -0
  159. package/{src → dist/esm}/cluster.js +9 -14
  160. package/dist/esm/cluster.js.map +1 -0
  161. package/dist/esm/index.js +5 -0
  162. package/dist/esm/index.js.map +1 -0
  163. package/dist/esm/middleware/404.js +11 -0
  164. package/dist/esm/middleware/404.js.map +1 -0
  165. package/dist/esm/middleware/cache.js +11 -0
  166. package/dist/esm/middleware/cache.js.map +1 -0
  167. package/dist/esm/middleware/connection.js +46 -0
  168. package/dist/esm/middleware/connection.js.map +1 -0
  169. package/dist/esm/middleware/context.js +17 -0
  170. package/dist/esm/middleware/context.js.map +1 -0
  171. package/dist/esm/middleware/cors.js +45 -0
  172. package/dist/esm/middleware/cors.js.map +1 -0
  173. package/dist/esm/middleware/swagger.js +14 -0
  174. package/dist/esm/middleware/swagger.js.map +1 -0
  175. package/dist/esm/middleware/user.js +45 -0
  176. package/dist/esm/middleware/user.js.map +1 -0
  177. package/{src → dist/esm}/oauth-providers/dropbox.js +13 -10
  178. package/dist/esm/oauth-providers/dropbox.js.map +1 -0
  179. package/{src → dist/esm}/oauth-providers/facebook.js +8 -10
  180. package/dist/esm/oauth-providers/facebook.js.map +1 -0
  181. package/{src → dist/esm}/oauth-providers/google.js +10 -12
  182. package/dist/esm/oauth-providers/google.js.map +1 -0
  183. package/dist/esm/oauth-providers/index.js +19 -0
  184. package/dist/esm/oauth-providers/index.js.map +1 -0
  185. package/{src → dist/esm}/oauth-providers/instagram.js +8 -10
  186. package/dist/esm/oauth-providers/instagram.js.map +1 -0
  187. package/dist/esm/oauth-providers/oauth-provider.js +22 -0
  188. package/dist/esm/oauth-providers/oauth-provider.js.map +1 -0
  189. package/{src → dist/esm}/oauth-providers/spotify.js +9 -11
  190. package/dist/esm/oauth-providers/spotify.js.map +1 -0
  191. package/dist/esm/package.json +3 -0
  192. package/dist/esm/routes/auth-change-password.js +70 -0
  193. package/dist/esm/routes/auth-change-password.js.map +1 -0
  194. package/dist/esm/routes/auth-delete.js +36 -0
  195. package/dist/esm/routes/auth-delete.js.map +1 -0
  196. package/dist/esm/routes/auth-forgot-password.js +61 -0
  197. package/dist/esm/routes/auth-forgot-password.js.map +1 -0
  198. package/dist/esm/routes/auth-reset-password.js +78 -0
  199. package/dist/esm/routes/auth-reset-password.js.map +1 -0
  200. package/dist/esm/routes/auth-signin.js +34 -0
  201. package/dist/esm/routes/auth-signin.js.map +1 -0
  202. package/dist/esm/routes/auth-signout.js +46 -0
  203. package/dist/esm/routes/auth-signout.js.map +1 -0
  204. package/dist/esm/routes/auth-signup.js +126 -0
  205. package/dist/esm/routes/auth-signup.js.map +1 -0
  206. package/dist/esm/routes/auth-state.js +13 -0
  207. package/dist/esm/routes/auth-state.js.map +1 -0
  208. package/dist/esm/routes/auth-update.js +115 -0
  209. package/dist/esm/routes/auth-update.js.map +1 -0
  210. package/dist/esm/routes/auth-verify-email.js +52 -0
  211. package/dist/esm/routes/auth-verify-email.js.map +1 -0
  212. package/dist/esm/routes/auth.js +51 -0
  213. package/dist/esm/routes/auth.js.map +1 -0
  214. package/dist/esm/routes/data-exists.js +21 -0
  215. package/dist/esm/routes/data-exists.js.map +1 -0
  216. package/dist/esm/routes/data-export.js +36 -0
  217. package/dist/esm/routes/data-export.js.map +1 -0
  218. package/dist/esm/routes/data-get.js +53 -0
  219. package/dist/esm/routes/data-get.js.map +1 -0
  220. package/dist/esm/routes/data-import.js +42 -0
  221. package/dist/esm/routes/data-import.js.map +1 -0
  222. package/dist/esm/routes/data-index-create.js +31 -0
  223. package/dist/esm/routes/data-index-create.js.map +1 -0
  224. package/dist/esm/routes/data-index-delete.js +23 -0
  225. package/dist/esm/routes/data-index-delete.js.map +1 -0
  226. package/dist/esm/routes/data-index-list.js +22 -0
  227. package/dist/esm/routes/data-index-list.js.map +1 -0
  228. package/dist/esm/routes/data-query.js +57 -0
  229. package/dist/esm/routes/data-query.js.map +1 -0
  230. package/dist/esm/routes/data-reflect.js +76 -0
  231. package/dist/esm/routes/data-reflect.js.map +1 -0
  232. package/dist/esm/routes/data-schema-get.js +26 -0
  233. package/dist/esm/routes/data-schema-get.js.map +1 -0
  234. package/dist/esm/routes/data-schema-set.js +20 -0
  235. package/dist/esm/routes/data-schema-set.js.map +1 -0
  236. package/dist/esm/routes/data-schema-test.js +32 -0
  237. package/dist/esm/routes/data-schema-test.js.map +1 -0
  238. package/dist/esm/routes/data-schemas-list.js +22 -0
  239. package/dist/esm/routes/data-schemas-list.js.map +1 -0
  240. package/dist/esm/routes/data-set.js +60 -0
  241. package/dist/esm/routes/data-set.js.map +1 -0
  242. package/dist/esm/routes/data-sync-changes.js +54 -0
  243. package/dist/esm/routes/data-sync-changes.js.map +1 -0
  244. package/dist/esm/routes/data-sync-mutations.js +54 -0
  245. package/dist/esm/routes/data-sync-mutations.js.map +1 -0
  246. package/dist/esm/routes/data-transaction.js +117 -0
  247. package/dist/esm/routes/data-transaction.js.map +1 -0
  248. package/dist/esm/routes/data-update.js +59 -0
  249. package/dist/esm/routes/data-update.js.map +1 -0
  250. package/dist/esm/routes/data.js +59 -0
  251. package/dist/esm/routes/data.js.map +1 -0
  252. package/dist/esm/routes/docs.js +244 -0
  253. package/dist/esm/routes/docs.js.map +1 -0
  254. package/dist/esm/routes/meta-info.js +66 -0
  255. package/dist/esm/routes/meta-info.js.map +1 -0
  256. package/dist/esm/routes/meta-ping.js +8 -0
  257. package/dist/esm/routes/meta-ping.js.map +1 -0
  258. package/dist/esm/routes/meta-stats.js +15 -0
  259. package/dist/esm/routes/meta-stats.js.map +1 -0
  260. package/dist/esm/routes/meta.js +13 -0
  261. package/dist/esm/routes/meta.js.map +1 -0
  262. package/dist/esm/routes/oauth2-init.js +39 -0
  263. package/dist/esm/routes/oauth2-init.js.map +1 -0
  264. package/dist/esm/routes/oauth2-refresh.js +30 -0
  265. package/dist/esm/routes/oauth2-refresh.js.map +1 -0
  266. package/dist/esm/routes/oauth2-signin.js +249 -0
  267. package/dist/esm/routes/oauth2-signin.js.map +1 -0
  268. package/dist/esm/routes/webmanager.js +23 -0
  269. package/dist/esm/routes/webmanager.js.map +1 -0
  270. package/dist/esm/rules.js +171 -0
  271. package/dist/esm/rules.js.map +1 -0
  272. package/dist/esm/schema/user.js +21 -0
  273. package/dist/esm/schema/user.js.map +1 -0
  274. package/dist/esm/server.js +344 -0
  275. package/dist/esm/server.js.map +1 -0
  276. package/dist/esm/settings/email.js +4 -0
  277. package/dist/esm/settings/email.js.map +1 -0
  278. package/dist/esm/settings/index.js +151 -0
  279. package/dist/esm/settings/index.js.map +1 -0
  280. package/dist/esm/shared/clients.js +23 -0
  281. package/dist/esm/shared/clients.js.map +1 -0
  282. package/dist/esm/shared/email.js +6 -0
  283. package/dist/esm/shared/email.js.map +1 -0
  284. package/dist/esm/shared/env.js +4 -0
  285. package/dist/esm/shared/env.js.map +1 -0
  286. package/dist/esm/shared/error.js +27 -0
  287. package/dist/esm/shared/error.js.map +1 -0
  288. package/dist/esm/shared/http.js +16 -0
  289. package/dist/esm/shared/http.js.map +1 -0
  290. package/dist/esm/shared/password.js +39 -0
  291. package/dist/esm/shared/password.js.map +1 -0
  292. package/dist/esm/shared/rootpath.js +12 -0
  293. package/dist/esm/shared/rootpath.js.map +1 -0
  294. package/dist/esm/shared/signin.js +125 -0
  295. package/dist/esm/shared/signin.js.map +1 -0
  296. package/{src/oauth-providers → dist/esm/shared}/simple-fetch.js +7 -10
  297. package/dist/esm/shared/simple-fetch.js.map +1 -0
  298. package/dist/esm/shared/tokens.js +72 -0
  299. package/dist/esm/shared/tokens.js.map +1 -0
  300. package/dist/esm/shared/validate.js +42 -0
  301. package/dist/esm/shared/validate.js.map +1 -0
  302. package/dist/esm/start.js +48 -0
  303. package/dist/esm/start.js.map +1 -0
  304. package/dist/esm/test.js +9 -0
  305. package/dist/esm/test.js.map +1 -0
  306. package/dist/esm/websocket/index.js +288 -0
  307. package/dist/esm/websocket/index.js.map +1 -0
  308. package/dist/esm/websocket/manager.js +12 -0
  309. package/dist/esm/websocket/manager.js.map +1 -0
  310. package/dist/esm/websocket/socket.io.js +71 -0
  311. package/dist/esm/websocket/socket.io.js.map +1 -0
  312. package/dist/types/auth.d.ts +3 -0
  313. package/dist/types/cluster.d.ts +1 -0
  314. package/dist/types/index.d.ts +4 -0
  315. package/dist/types/middleware/404.d.ts +7 -0
  316. package/dist/types/middleware/cache.d.ts +3 -0
  317. package/dist/types/middleware/connection.d.ts +7 -0
  318. package/dist/types/middleware/context.d.ts +3 -0
  319. package/dist/types/middleware/cors.d.ts +25 -0
  320. package/dist/types/middleware/swagger.d.ts +3 -0
  321. package/dist/types/middleware/user.d.ts +2 -0
  322. package/dist/types/oauth-providers/dropbox.d.ts +52 -0
  323. package/dist/types/oauth-providers/facebook.d.ts +41 -0
  324. package/dist/types/oauth-providers/google.d.ts +43 -0
  325. package/dist/types/oauth-providers/index.d.ts +10 -0
  326. package/dist/types/oauth-providers/instagram.d.ts +50 -0
  327. package/dist/types/oauth-providers/oauth-provider.d.ts +74 -0
  328. package/dist/types/oauth-providers/spotify.d.ts +53 -0
  329. package/dist/types/routes/auth-change-password.d.ts +20 -0
  330. package/dist/types/routes/auth-delete.d.ts +16 -0
  331. package/dist/types/routes/auth-forgot-password.d.ts +16 -0
  332. package/dist/types/routes/auth-reset-password.d.ts +23 -0
  333. package/dist/types/routes/auth-signin.d.ts +24 -0
  334. package/dist/types/routes/auth-signout.d.ts +14 -0
  335. package/dist/types/routes/auth-signup.d.ts +32 -0
  336. package/dist/types/routes/auth-state.d.ts +13 -0
  337. package/dist/types/routes/auth-update.d.ts +33 -0
  338. package/dist/types/routes/auth-verify-email.d.ts +21 -0
  339. package/dist/types/routes/auth.d.ts +6 -0
  340. package/dist/types/routes/data-exists.d.ts +9 -0
  341. package/dist/types/routes/data-export.d.ts +10 -0
  342. package/dist/types/routes/data-get.d.ts +14 -0
  343. package/dist/types/routes/data-import.d.ts +13 -0
  344. package/dist/types/routes/data-index-create.d.ts +51 -0
  345. package/dist/types/routes/data-index-delete.d.ts +17 -0
  346. package/dist/types/routes/data-index-list.d.ts +21 -0
  347. package/dist/types/routes/data-query.d.ts +49 -0
  348. package/dist/types/routes/data-reflect.d.ts +29 -0
  349. package/dist/types/routes/data-schema-get.d.ts +11 -0
  350. package/dist/types/routes/data-schema-set.d.ts +19 -0
  351. package/dist/types/routes/data-schema-test.d.ts +21 -0
  352. package/dist/types/routes/data-schemas-list.d.ts +11 -0
  353. package/dist/types/routes/data-set.d.ts +27 -0
  354. package/dist/types/routes/data-sync-changes.d.ts +28 -0
  355. package/dist/types/routes/data-sync-mutations.d.ts +28 -0
  356. package/dist/types/routes/data-transaction.d.ts +34 -0
  357. package/dist/types/routes/data-update.d.ts +27 -0
  358. package/dist/types/routes/data.d.ts +3 -0
  359. package/dist/types/routes/docs.d.ts +3 -0
  360. package/dist/types/routes/meta-info.d.ts +11 -0
  361. package/dist/types/routes/meta-ping.d.ts +7 -0
  362. package/dist/types/routes/meta-stats.d.ts +13 -0
  363. package/dist/types/routes/meta.d.ts +3 -0
  364. package/dist/types/routes/oauth2-init.d.ts +13 -0
  365. package/dist/types/routes/oauth2-refresh.d.ts +17 -0
  366. package/dist/types/routes/oauth2-signin.d.ts +15 -0
  367. package/dist/types/routes/webmanager.d.ts +3 -0
  368. package/dist/types/rules.d.ts +41 -0
  369. package/dist/types/schema/user.d.ts +85 -0
  370. package/dist/types/server.d.ts +108 -0
  371. package/dist/types/settings/email.d.ts +14 -0
  372. package/dist/types/settings/index.d.ts +164 -0
  373. package/dist/types/shared/clients.d.ts +46 -0
  374. package/dist/types/shared/email.d.ts +34 -0
  375. package/dist/types/shared/env.d.ts +42 -0
  376. package/dist/types/shared/error.d.ts +15 -0
  377. package/dist/types/shared/http.d.ts +16 -0
  378. package/dist/types/shared/password.d.ts +19 -0
  379. package/dist/types/shared/rootpath.d.ts +2 -0
  380. package/dist/types/shared/signin.d.ts +31 -0
  381. package/dist/types/shared/simple-fetch.d.ts +21 -0
  382. package/dist/types/shared/tokens.d.ts +23 -0
  383. package/dist/types/shared/validate.d.ts +22 -0
  384. package/dist/types/start.d.ts +1 -0
  385. package/dist/types/test.d.ts +1 -0
  386. package/dist/types/websocket/index.d.ts +2 -0
  387. package/dist/types/websocket/manager.d.ts +99 -0
  388. package/dist/types/websocket/socket.io.d.ts +10 -0
  389. package/package.json +27 -11
  390. package/src/auth.ts +87 -0
  391. package/src/cluster.ts +62 -0
  392. package/src/index.ts +4 -0
  393. package/src/middleware/404.ts +13 -0
  394. package/src/middleware/cache.ts +15 -0
  395. package/src/middleware/connection.ts +48 -0
  396. package/src/middleware/context.ts +23 -0
  397. package/src/middleware/cors.ts +49 -0
  398. package/src/middleware/swagger.ts +19 -0
  399. package/src/middleware/user.ts +51 -0
  400. package/src/{ts/oauth-providers → oauth-providers}/dropbox.ts +6 -5
  401. package/src/{ts/oauth-providers → oauth-providers}/facebook.ts +6 -5
  402. package/src/{ts/oauth-providers → oauth-providers}/google.ts +6 -5
  403. package/src/oauth-providers/index.ts +21 -0
  404. package/src/{ts/oauth-providers → oauth-providers}/instagram.ts +6 -5
  405. package/src/{ts/oauth-providers → oauth-providers}/oauth-provider.ts +14 -4
  406. package/src/{ts/oauth-providers → oauth-providers}/spotify.ts +6 -5
  407. package/src/placeholder.d.ts +12 -0
  408. package/src/routes/auth-change-password.ts +89 -0
  409. package/src/{ts/routes → routes}/auth-change-password.yaml +0 -2
  410. package/src/routes/auth-delete.ts +47 -0
  411. package/src/{ts/routes → routes}/auth-delete.yaml +0 -0
  412. package/src/routes/auth-forgot-password.ts +73 -0
  413. package/src/{ts/routes → routes}/auth-forgot-password.yaml +0 -0
  414. package/src/routes/auth-reset-password.ts +93 -0
  415. package/src/{ts/routes → routes}/auth-reset-password.yaml +0 -0
  416. package/src/routes/auth-signin.ts +55 -0
  417. package/src/{ts/routes → routes}/auth-signin.yaml +5 -5
  418. package/src/routes/auth-signout.ts +61 -0
  419. package/src/{ts/routes → routes}/auth-signout.yaml +0 -0
  420. package/src/routes/auth-signup.ts +161 -0
  421. package/src/{ts/routes → routes}/auth-signup.yaml +15 -0
  422. package/src/routes/auth-state.ts +20 -0
  423. package/src/{ts/routes → routes}/auth-state.yaml +0 -0
  424. package/src/routes/auth-update.ts +147 -0
  425. package/src/{ts/routes → routes}/auth-update.yaml +22 -2
  426. package/src/routes/auth-verify-email.ts +67 -0
  427. package/src/{ts/routes → routes}/auth-verify-email.yaml +0 -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 +80 -0
  456. package/src/routes/data-set.yaml +77 -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 +82 -0
  462. package/src/routes/data-transaction-start.yaml +58 -0
  463. package/src/routes/data-transaction.ts +159 -0
  464. package/src/routes/data-update.ts +81 -0
  465. package/src/routes/data-update.yaml +77 -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/{ts/routes → routes}/oauth2-init.yaml +0 -0
  477. package/src/routes/oauth2-refresh.ts +39 -0
  478. package/src/{ts/routes → routes}/oauth2-refresh.yaml +0 -0
  479. package/src/routes/oauth2-signin.ts +282 -0
  480. package/src/{ts/routes → routes}/oauth2-signin.yaml +0 -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 +418 -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 +26 -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 +90 -0
  503. package/tsconfig-cjs.json +10 -0
  504. package/tsconfig.json +13 -5
  505. package/webmanager/acebase-client-browser.min.js +16 -0
  506. package/{src/webmanager → webmanager}/index.html +2 -2
  507. package/{src/webmanager → webmanager}/index.js +3 -6
  508. package/src/acebase-server.js +0 -3060
  509. package/src/index.d.ts +0 -212
  510. package/src/index.js +0 -2
  511. package/src/routes/docs.js +0 -97
  512. package/src/ts/routes/docs.ts +0 -100
package/src/auth.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { ColorStyle, SimpleCache } from "acebase-core";
2
+ import { randomBytes } from "crypto";
3
+ import { DbUserAccountDetails } from "./schema/user";
4
+ import { RouteInitEnvironment } from "./shared/env";
5
+ import { createPasswordHash, generatePassword, getOldPasswordHash, getPasswordHash } from "./shared/password";
6
+
7
+ export const setupAuthentication = async (env: RouteInitEnvironment) => {
8
+
9
+ // Setup auth cache
10
+ env.authCache = new SimpleCache<string, DbUserAccountDetails>({ expirySeconds: 300, cloneValues: false, maxEntries: 1000 });
11
+
12
+ // Get or generate a salt to hash public tokens with
13
+ await env.securityRef.child('token_salt').transaction(snap => {
14
+ env.tokenSalt = snap.val();
15
+ if (!env.tokenSalt) {
16
+ let length = 256;
17
+ env.tokenSalt = randomBytes(Math.ceil(length/2)).toString('hex').slice(0,length);
18
+ return env.tokenSalt;
19
+ }
20
+ });
21
+
22
+ // Setup admin account
23
+ await env.authRef.child('admin').transaction(snap => {
24
+
25
+ let adminAccount: DbUserAccountDetails = snap.val();
26
+ if (adminAccount === null) {
27
+ // Use provided default password, or generate one:
28
+ const adminPassword = env.config.auth.defaultAdminPassword || generatePassword();
29
+
30
+ const pwd = createPasswordHash(adminPassword);
31
+ adminAccount = {
32
+ uid: null,
33
+ username: 'admin',
34
+ email: null, // no email address for admin
35
+ display_name: `${env.db.name} AceBase admin`,
36
+ password: pwd.hash,
37
+ password_salt: pwd.salt,
38
+ change_password: true, // flags that password must be changed. Not implemented yet
39
+ created: new Date(),
40
+ access_token: null, // Will be set upon login, so bearer authentication strategy can find user with this token
41
+ settings: {}
42
+ };
43
+ env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
44
+ env.debug.warn(``.colorize(ColorStyle.red));
45
+ env.debug.warn(`IMPORTANT: Admin account created`.colorize(ColorStyle.red));
46
+ env.debug.warn(`You need the admin account to remotely administer the database`.colorize(ColorStyle.red));
47
+ env.debug.warn(`Use the following credentials to authenticate an AceBaseClient:`.colorize(ColorStyle.red));
48
+ env.debug.warn(``);
49
+ env.debug.warn(` username: admin`.colorize(ColorStyle.red));
50
+ env.debug.warn(` password: ${adminPassword}`.colorize(ColorStyle.red));
51
+ env.debug.warn(``);
52
+ env.debug.warn(`THIS IS ONLY SHOWN ONCE!`.colorize(ColorStyle.red));
53
+ env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
54
+ return adminAccount; // Save it
55
+ }
56
+ else if (env.config.auth.defaultAdminPassword) {
57
+ // Check if the default password was changed
58
+ let passwordHash;
59
+ if (!adminAccount.password_salt) {
60
+ // Old md5 password hash?
61
+ passwordHash = getOldPasswordHash(env.config.auth.defaultAdminPassword);
62
+ }
63
+ else {
64
+ passwordHash = getPasswordHash(env.config.auth.defaultAdminPassword, adminAccount.password_salt);
65
+ }
66
+ if (adminAccount.password === passwordHash) {
67
+ env.debug.warn(`WARNING: default password for admin user was not changed!`.colorize(ColorStyle.red));
68
+
69
+ if (!adminAccount.password_salt) {
70
+ // Create new password hash
71
+ const pwd = createPasswordHash(env.config.auth.defaultAdminPassword);
72
+ adminAccount.password = pwd.hash;
73
+ adminAccount.password_salt = pwd.salt;
74
+ return adminAccount; // Save it
75
+ }
76
+ }
77
+ }
78
+ });
79
+
80
+ // Make sure indexes are present for quick user lookups
81
+ env.authDb.indexes.create(env.authRef.path, 'username');
82
+ env.authDb.indexes.create(env.authRef.path, 'email');
83
+ env.authDb.indexes.create(env.authRef.path, 'access_token');
84
+
85
+ };
86
+
87
+ export default setupAuthentication;
package/src/cluster.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { AceBase } from 'acebase';
2
+ import { AceBaseServer } from './server';
3
+ import { AceBaseServerSettings } from './settings';
4
+ import * as cluster from 'cluster';
5
+ import * as os from 'os';
6
+ const numCPUs = 2; //os.cpus().length;
7
+
8
+ /**
9
+ * Node.js cluster example. You can use this as a reference how to create an AceBaseServer cluster using Node.js'
10
+ * built-in cluster functionality.
11
+ *
12
+ * If you want to run a pm2 or cloud-based cluster instead, do NOT use this code.
13
+ * To do that, see https://github.com/appy-one/acebase-ipc-server
14
+ *
15
+ */
16
+
17
+ let dbname = "default";
18
+ let options: AceBaseServerSettings = { /* default options */ }; // Load from cluster.config.js!
19
+ options.authentication = { enabled: false };
20
+ options.https = { enabled: false };
21
+
22
+ if (cluster.isMaster) {
23
+ // Startup master
24
+ console.log(`Starting database server cluster with ${numCPUs} workers`);
25
+ const master = new AceBase(dbname, options);
26
+ master.once('ready', () => {
27
+ console.log(`Master database server started on process ${process.pid}`);
28
+ });
29
+
30
+ for (let i = 0; i < numCPUs; i++) {
31
+ const worker = cluster.fork();
32
+ worker.on('disconnect', () => {
33
+ console.error(`worker ${worker.process.pid} disconnected`);
34
+ });
35
+ worker.on('message', (msg) => {
36
+ if (msg === 'acebase-server-shutdown') {
37
+ // We could handle shutdown message here to kill the worker safely, but we'll do it in the worker threads instead: see below
38
+ // worker.kill();
39
+ }
40
+ });
41
+ }
42
+
43
+ cluster.on('exit', (worker, code, signal) => {
44
+ console.error(`worker ${worker.process.pid} died`);
45
+ });
46
+ }
47
+ else {
48
+ console.log(`Worker ${process.pid} is running`);
49
+
50
+ const server = new AceBaseServer(dbname, options);
51
+ server.ready(() => {
52
+ console.log(`Worker database server started on process ${process.pid}`);
53
+ });
54
+ // Handle shutdown event to exit the worker process safely
55
+ server.on('shutdown', () => {
56
+ process.exit();
57
+ });
58
+ // Other option:
59
+ // process.on('acebase-server-shutdown', () => {
60
+ // process.exit();
61
+ // });
62
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { AceBaseServer } from './server';
2
+ export { AceBaseServerSettings, AceBaseServerHttpsSettings, AceBaseServerTransactionSettings, AceBaseServerAuthenticationSettings } from './settings';
3
+ export * from './shared/email';
4
+ export * from './oauth-providers';
@@ -0,0 +1,13 @@
1
+ import { RouteInitEnvironment } from "../shared/env";
2
+
3
+ /**
4
+ * Adds 404 middleware. Add this as very last handler!
5
+ * @param env
6
+ */
7
+ export const addMiddleware = (env: RouteInitEnvironment) => {
8
+ env.app.use((req, res, next) => {
9
+ res.status(404).send('Not Found');
10
+ });
11
+ };
12
+
13
+ export default addMiddleware;
@@ -0,0 +1,15 @@
1
+ import { RouteInitEnvironment, RouteRequest } from "../shared/env";
2
+
3
+ export const addMiddleware = (env: RouteInitEnvironment) => {
4
+
5
+ env.app.use((req: RouteRequest, res, next) => {
6
+ // Disable cache for GET requests to make sure browsers do not use cached responses
7
+ if (req.method === 'GET') {
8
+ res.setHeader('Cache-Control', 'no-cache');
9
+ }
10
+ next();
11
+ });
12
+
13
+ };
14
+
15
+ export default addMiddleware;
@@ -0,0 +1,48 @@
1
+ import type { Duplex } from 'stream';
2
+ import type { RouteInitEnvironment } from '../shared/env';
3
+
4
+ /**
5
+ * Adds connection management middleware. Add this as very first handler!
6
+ * @param env
7
+ */
8
+ export const addMiddleware = (env: RouteInitEnvironment) => {
9
+
10
+ const sockets = new Set<Duplex>();
11
+ let terminating = false;
12
+ const destroySocket = (socket: Duplex) => {
13
+ socket.destroy();
14
+ };
15
+ const addConnection = (socket: Duplex) => {
16
+ // console.log(`event: server.connection`);
17
+ if (terminating) {
18
+ destroySocket(socket);
19
+ }
20
+ else {
21
+ sockets.add(socket);
22
+ socket.once('close', () => {
23
+ // console.log(`event: socket.close`);
24
+ sockets.delete(socket);
25
+ });
26
+ }
27
+ };
28
+ env.server.on('connection', addConnection);
29
+ env.server.on('secureConnection', addConnection);
30
+
31
+ // Don't enable this: it'll make every other request real slow
32
+ // env.app.use((req, res, next) => {
33
+ // res.setHeader('Connection', 'close');
34
+ // next();
35
+ // });
36
+
37
+ const terminate = () => {
38
+ terminating = true;
39
+ console.warn(`Terminating ${sockets.size} open connections`);
40
+ sockets.forEach(socket => {
41
+ try { destroySocket(socket); }
42
+ catch (err) { console.error(`Cannot destroy socket: ${err.message}`); }
43
+ });
44
+ };
45
+ return terminate;
46
+ };
47
+
48
+ export default addMiddleware;
@@ -0,0 +1,23 @@
1
+ import { RouteInitEnvironment, RouteRequest } from "../shared/env";
2
+
3
+ export const addMiddleware = (env: RouteInitEnvironment) => {
4
+
5
+ env.app.use((req: RouteRequest, res, next) => {
6
+ // Setup AceBase context, to allow clients to pass contextual info with data updates,
7
+ // that will be sent along to data event subscribers on affected data.
8
+
9
+ const context = req.get('AceBase-Context') || '{}';
10
+ try {
11
+ req.context = JSON.parse(context);
12
+ }
13
+ catch(err) {
14
+ env.debug.error(`Failed to parse AceBase-Context header: "${context}" in request at ${req.url} from client ${req.ip}`);
15
+ return res.status(500).end('Invalid request context');
16
+ }
17
+
18
+ next();
19
+ });
20
+
21
+ };
22
+
23
+ export default addMiddleware;
@@ -0,0 +1,49 @@
1
+ import { RouteInitEnvironment } from "../shared/env";
2
+
3
+ /**
4
+ * Gets CORS options that are compatible with the 'cors' package (used by Socket.IO 3+)
5
+ * @param allowedOrigins
6
+ * @returns
7
+ */
8
+ export const getCorsOptions = (allowedOrigins: string) => {
9
+ return {
10
+ origin: allowedOrigins === '*' ? true : allowedOrigins === '' ? false : allowedOrigins.split(/,\s*/),
11
+ methods: 'GET,PUT,POST,DELETE,OPTIONS',
12
+ allowedHeaders: 'Content-Type, Authorization, Content-Length, Accept, Origin, X-Requested-With, AceBase-Context'
13
+ };
14
+ };
15
+
16
+ /**
17
+ * Gets CORS headers that can be sent in preflight (OPTIONS) requests
18
+ * @param allowedOrigins configured allowed origin(s). Examples: `'https://my.server.com'` for a specific allowed origin, `'*'` for any origin (returns current origin), `''` to disable CORS (only allows localhost), or `'http://server1.com,https://server1.com,https://server2.com'` for multiple allowed origins
19
+ * @param currentOrigin current origin from request headers
20
+ * @returns
21
+ */
22
+ export const getCorsHeaders = (allowedOrigins: string, currentOrigin: string) => {
23
+ const corsOptions = getCorsOptions(allowedOrigins);
24
+ const origins = typeof corsOptions.origin === 'boolean'
25
+ ? corsOptions.origin ? currentOrigin ?? '*' : ''
26
+ : corsOptions.origin instanceof Array ? corsOptions.origin.join(',') : corsOptions.origin;
27
+ return {
28
+ 'Access-Control-Allow-Origin': origins,
29
+ 'Access-Control-Allow-Methods': corsOptions.methods,
30
+ 'Access-Control-Allow-Headers': corsOptions.allowedHeaders,
31
+ 'Access-Control-Expose-Headers': 'Date, AceBase-Context' // Prevent browsers from stripping these headers from the response for programmatic access in cross-origin requests
32
+ };
33
+ };
34
+
35
+ export const addMiddleware = (env: RouteInitEnvironment) => {
36
+ env.app.use((req, res, next) => {
37
+ const headers = getCorsHeaders(env.config.allowOrigin, req.headers.origin);
38
+ for (let name in headers) {
39
+ res.setHeader(name, headers[name]);
40
+ }
41
+ if (req.method === 'OPTIONS') {
42
+ // Return 200 OK
43
+ return res.status(200).end();
44
+ }
45
+ next();
46
+ });
47
+ };
48
+
49
+ export default addMiddleware;
@@ -0,0 +1,19 @@
1
+ import { RouteInitEnvironment, RouteRequest } from "../shared/env";
2
+
3
+ export const addMiddleware = (env: RouteInitEnvironment) => {
4
+
5
+ env.app.use((req: RouteRequest, res, next) => {
6
+ // Swagger UI escapes path variables, so "some/path" in a path variable of an endpoint becomes "some%2Fpath". This middleware fixes that
7
+ if (req.path.includes('%2F')) {
8
+ const [url, query] = req.url.split('?');
9
+ const newUrl = url.replace(/\%2F/g, '/') + (query ? `?${query}` : '');
10
+ env.debug.warn(`API: replacing escaped slashes in request path for Swagger UI: ${req.url} -> ${newUrl}`);
11
+ req.url = newUrl;
12
+ }
13
+
14
+ next();
15
+ });
16
+
17
+ };
18
+
19
+ export default addMiddleware;
@@ -0,0 +1,51 @@
1
+ import { RouteInitEnvironment, RouteRequest } from "../shared/env";
2
+ import { sendNotAuthenticatedError } from "../shared/error";
3
+ import { signIn } from "../shared/signin";
4
+ import { decodePublicAccessToken } from "../shared/tokens";
5
+
6
+ export const addMiddleware = (env: RouteInitEnvironment) => {
7
+
8
+ // Add bearer authentication middleware
9
+ env.app.use(async (req: RouteRequest<any, any, any, { auth_token?: string }>, res, next) => {
10
+
11
+ let authorization = req.get('Authorization');
12
+ if (typeof authorization !== 'string' && 'auth_token' in req.query) {
13
+ // Enables browser calls to be authenticated
14
+ if (req.path.startsWith('/export/')) {
15
+ // For now, only allow this if the intention is to call '/export' api call
16
+ // In the future, use these prerequisites:
17
+ // - user must be currently authenticated (in cache)
18
+ // - ip address must match the token
19
+ authorization = 'Bearer ' + req.query.auth_token;
20
+ }
21
+ }
22
+
23
+ if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
24
+ const token = authorization.slice(7);
25
+ let tokenDetails: ReturnType<typeof decodePublicAccessToken>;
26
+ try {
27
+ tokenDetails = decodePublicAccessToken(token, env.tokenSalt);
28
+ }
29
+ catch (err) {
30
+ return sendNotAuthenticatedError(res, 'invalid_token', 'The passed token is invalid. Sign in again');
31
+ }
32
+
33
+ // Is this token cached?
34
+ req.user = env.authCache.get(tokenDetails.uid);
35
+ if (!req.user) {
36
+ // Query database to get user for this token
37
+ try {
38
+ await signIn({ method: 'private_token', access_token: tokenDetails.access_token }, env, req);
39
+ }
40
+ catch (err) {
41
+ return sendNotAuthenticatedError(res, err.code, err.message);
42
+ }
43
+ }
44
+
45
+ if (req.user.is_disabled === true) {
46
+ return sendNotAuthenticatedError(res, 'account_disabled', 'Your account has been disabled. Contact your database administrator');
47
+ }
48
+ }
49
+ next();
50
+ });
51
+ };
@@ -1,5 +1,5 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
2
- import { fetch } from './simple-fetch';
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
5
5
  * Details of your app to access the Dropbox API
@@ -48,9 +48,10 @@ interface IDropboxUser {
48
48
  }
49
49
  team_member_id?: string
50
50
  }
51
- export class DropboxAuthProvider implements IOAuth2Provider {
51
+ export class DropboxAuthProvider extends OAuth2Provider {
52
52
 
53
- constructor(private settings: IDropboxAuthSettings) {
53
+ constructor(settings: IDropboxAuthSettings) {
54
+ super(settings);
54
55
  if (!settings.scopes) { settings.scopes = []; }
55
56
  if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) { settings.scopes.push('account_info.read'); }
56
57
  }
@@ -66,7 +67,7 @@ export class DropboxAuthProvider implements IOAuth2Provider {
66
67
  * @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
67
68
  * @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
68
69
  */
69
- async init(info: { redirect_url: string, state?: string, options?: { locale?: string, require_role?: string, disable_signup?: boolean, force_reapprove?: boolean, force_reauthentication?: boolean } }) {
70
+ async init(info: OAuth2ProviderInitInfo) {
70
71
  // Return url to get authorization code with
71
72
  const options = info.options || {};
72
73
  const authUrl = `https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&locale=${options.locale || ''}&require_role=${options.require_role || ''}&force_reauthentication=${options.force_reauthentication === true}&force_reapprove=${options.force_reapprove === true}&disable_signup=${options.disable_signup === true}&state=${encodeURIComponent(info.state)}`;
@@ -1,5 +1,5 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
2
- import { fetch } from './simple-fetch';
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
5
5
  * Details of your app to access the Facebook Graph API
@@ -28,9 +28,10 @@ interface IFacebookUser {
28
28
  }
29
29
  }
30
30
  }
31
- export class FacebookAuthProvider implements IOAuth2Provider {
31
+ export class FacebookAuthProvider extends OAuth2Provider {
32
32
 
33
- constructor(private settings: IFacebookAuthSettings) {
33
+ constructor(settings: IFacebookAuthSettings) {
34
+ super(settings);
34
35
  if (!settings.scopes) { settings.scopes = []; }
35
36
  if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
36
37
  }
@@ -40,7 +41,7 @@ export class FacebookAuthProvider implements IOAuth2Provider {
40
41
  * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
41
42
  * @param info.state Optional state that will be passed to redirectUri by spotify
42
43
  */
43
- async init(info: { redirect_url: string, state?: string }) {
44
+ async init(info: OAuth2ProviderInitInfo) {
44
45
  // Return url to get authorization code with
45
46
  const authUrl = `https://www.facebook.com/v7.0/dialog/oauth?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
46
47
  return authUrl;
@@ -1,5 +1,5 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOpenIDToken, IOpenIDConfiguration, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
2
- import { fetch } from './simple-fetch';
1
+ import { IOAuth2ProviderSettings, IOpenIDToken, IOpenIDConfiguration, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2ProviderInitInfo, OAuth2Provider } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
5
5
  * Details of your app to access the Google API. See https://developers.google.com/identity/protocols/oauth2/scopes
@@ -43,11 +43,12 @@ interface IGoogleUser {
43
43
  updated_at: number
44
44
  }
45
45
 
46
- export class GoogleAuthProvider implements IOAuth2Provider {
46
+ export class GoogleAuthProvider extends OAuth2Provider {
47
47
 
48
48
  _config: IOpenIDConfiguration
49
49
 
50
- constructor(private settings: IGoogleAuthSettings) {
50
+ constructor(settings: IGoogleAuthSettings) {
51
+ super(settings);
51
52
  if (!settings.scopes) { settings.scopes = []; }
52
53
  if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
53
54
  if (!settings.scopes.includes('profile')) { settings.scopes.push('profile'); }
@@ -66,7 +67,7 @@ export class GoogleAuthProvider implements IOAuth2Provider {
66
67
  * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
67
68
  * @param info.state Optional state that will be passed to redirectUri by spotify
68
69
  */
69
- async init(info: { redirect_url: string, state?: string }) {
70
+ async init(info: OAuth2ProviderInitInfo) {
70
71
  // Return url to get authorization code with
71
72
  // See https://developers.google.com/identity/protocols/oauth2/web-server#httprest
72
73
 
@@ -0,0 +1,21 @@
1
+ import { DropboxAuthProvider } from './dropbox';
2
+ import { FacebookAuthProvider } from './facebook';
3
+ import { GoogleAuthProvider } from './google';
4
+ import { InstagramAuthProvider } from './instagram';
5
+ import { OAuth2Provider } from './oauth-provider';
6
+ import { SpotifyAuthProvider } from './spotify';
7
+
8
+ export { DropboxAuthProvider, IDropboxAuthSettings } from './dropbox';
9
+ export { FacebookAuthProvider, IFacebookAuthSettings } from './facebook';
10
+ export { GoogleAuthProvider, IGoogleAuthSettings } from './google';
11
+ export { InstagramAuthProvider, IInstagramAuthSettings } from './instagram';
12
+ export { SpotifyAuthProvider, ISpotifyAuthSettings } from './spotify';
13
+
14
+ const oAuth2Providers: { [key: string]: typeof OAuth2Provider } = {
15
+ dropbox: DropboxAuthProvider,
16
+ facebook: FacebookAuthProvider,
17
+ google: GoogleAuthProvider,
18
+ instagram: InstagramAuthProvider,
19
+ spotify: SpotifyAuthProvider
20
+ }
21
+ export default oAuth2Providers;
@@ -1,5 +1,5 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams } from "./oauth-provider";
2
- import { fetch } from './simple-fetch';
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
5
5
  * Details of your app to access the Legacy Instagram API.
@@ -28,9 +28,10 @@ interface IInstagramUser {
28
28
  followed_by: number
29
29
  }
30
30
  }
31
- export class InstagramAuthProvider implements IOAuth2Provider {
31
+ export class InstagramAuthProvider extends OAuth2Provider {
32
32
 
33
- constructor(private settings: IInstagramAuthSettings) {
33
+ constructor(settings: IInstagramAuthSettings) {
34
+ super(settings);
34
35
  if (!settings.scopes) { settings.scopes = []; }
35
36
  if (!settings.scopes.includes('basic')) { settings.scopes.push('basic'); }
36
37
 
@@ -44,7 +45,7 @@ export class InstagramAuthProvider implements IOAuth2Provider {
44
45
  * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
45
46
  * @param info.state Optional state that will be passed to redirectUri by spotify
46
47
  */
47
- async init(info: { redirect_url: string, state?: string }) {
48
+ async init(info: OAuth2ProviderInitInfo) {
48
49
  // Return url to get authorization code with
49
50
  // See https://www.instagram.com/developer/authorization/
50
51
  const authUrl = `https://api.instagram.com/oauth/authorize/?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
@@ -18,10 +18,20 @@ export interface IOAuth2TokenResult {
18
18
  expires_in?: number,
19
19
  refresh_token?: string
20
20
  }
21
- export interface IOAuth2Provider {
22
- init(info: { redirect_url: string, state?: string, options?: any }): Promise<string>
23
- getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult>
24
- getUserInfo(access_token: string): Promise<{ id: string, name: string, display_name: string, picture?: Array<{ width?: number, height?: number, url: string }>, email: string, email_verified: boolean, other?: { [key:string]: string|number|boolean } }>
21
+
22
+ export type OAuth2ProviderInitInfo = { redirect_url: string, state?: string, options?: any };
23
+ export type OAuth2ProviderUserInfo = { id: string, name: string, display_name: string, picture?: Array<{ width?: number, height?: number, url: string }>, email: string, email_verified: boolean, other?: { [key:string]: string|number|boolean } };
24
+ // export interface IOAuth2Provider {
25
+ // init(info: OAuth2ProviderInitInfo): Promise<string>;
26
+ // getAccessToken(param: OAuth2ProviderGetAccessTokenParams): Promise<IOAuth2TokenResult>;
27
+ // getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo>;
28
+ // }
29
+ class NotImplementedError extends Error { constructor() { super('Not implemented'); } }
30
+ export class OAuth2Provider { //implements IOAuth2Provider
31
+ constructor(protected settings: IOAuth2ProviderSettings) {}
32
+ init(info: OAuth2ProviderInitInfo): Promise<string> { throw new NotImplementedError(); };
33
+ getAccessToken(param: IOAuth2AuthCodeParams|IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult> { throw new NotImplementedError(); };;
34
+ getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo> { throw new NotImplementedError(); };;
25
35
  }
26
36
  // For OAuth2.0 providers with id_token in getAccessToken, see https://auth0.com/docs/tokens/concepts/jwts
27
37
  export interface IOpenIDToken {
@@ -1,5 +1,5 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
2
- import { fetch } from './simple-fetch';
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
5
5
  * Details of your app to access the Spotify API
@@ -28,9 +28,10 @@ interface ISpotifyUser {
28
28
  type: 'user',
29
29
  uri: string
30
30
  }
31
- export class SpotifyAuthProvider implements IOAuth2Provider {
31
+ export class SpotifyAuthProvider extends OAuth2Provider {
32
32
 
33
- constructor(private settings: ISpotifyAuthSettings) {
33
+ constructor(settings: ISpotifyAuthSettings) {
34
+ super(settings);
34
35
  if (!settings.scopes) { settings.scopes = []; }
35
36
  if (!settings.scopes.includes('user-read-email')) { settings.scopes.push('user-read-email'); }
36
37
  if (!settings.scopes.includes('user-read-private')) { settings.scopes.push('user-read-private'); }
@@ -41,7 +42,7 @@ export class SpotifyAuthProvider implements IOAuth2Provider {
41
42
  * @param info.redirectUrl Url spotify will redirect to after authorizing
42
43
  * @param info.state Optional state that will be passed to redirectUri by spotify
43
44
  */
44
- async init(info: { redirect_url: string, state?: string }) {
45
+ async init(info: OAuth2ProviderInitInfo) {
45
46
  // Return url to get authorization code with
46
47
  const authUrl = `https://accounts.spotify.com/authorize?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
47
48
  return authUrl;
@@ -0,0 +1,12 @@
1
+
2
+ /**
3
+ * When using `@types/node@10.17.60` to check for backward compatibility with Node.js 10,
4
+ * tsc will throw errors on `@types/fs-extra` that references types `fs.Dir`,
5
+ * `fs.OpenDirOptions` and `fs.RmDirOptions`, which are not declared.
6
+ * @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44946
7
+ */
8
+ declare module 'fs' {
9
+ interface Dir {}
10
+ interface OpenDirOptions {}
11
+ interface RmDirOptions {}
12
+ }