acebase-server 1.13.3 → 1.15.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 (452) hide show
  1. package/create-package-files +25 -0
  2. package/dist/cjs/auth.js.map +1 -0
  3. package/dist/cjs/cluster.js.map +1 -0
  4. package/dist/cjs/index.d.ts +1 -1
  5. package/dist/cjs/index.js.map +1 -0
  6. package/dist/cjs/logger.js.map +1 -0
  7. package/dist/cjs/middleware/404.js.map +1 -0
  8. package/dist/cjs/middleware/admin-only.js.map +1 -0
  9. package/dist/cjs/middleware/cache.js.map +1 -0
  10. package/dist/cjs/middleware/connection.js.map +1 -0
  11. package/dist/cjs/middleware/context.js.map +1 -0
  12. package/dist/cjs/middleware/cors.js.map +1 -0
  13. package/dist/cjs/middleware/swagger.js.map +1 -0
  14. package/dist/cjs/middleware/user.js.map +1 -0
  15. package/dist/cjs/oauth-providers/dropbox.js.map +1 -0
  16. package/dist/cjs/oauth-providers/facebook.js.map +1 -0
  17. package/dist/cjs/oauth-providers/google.js.map +1 -0
  18. package/dist/cjs/oauth-providers/index.js.map +1 -0
  19. package/dist/cjs/oauth-providers/instagram.js.map +1 -0
  20. package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -0
  21. package/dist/cjs/oauth-providers/spotify.js.map +1 -0
  22. package/dist/cjs/routes/auth-change-password.js.map +1 -0
  23. package/dist/cjs/routes/auth-delete.js.map +1 -0
  24. package/dist/cjs/routes/auth-forgot-password.js.map +1 -0
  25. package/dist/cjs/routes/auth-reset-password.js.map +1 -0
  26. package/dist/cjs/routes/auth-signin.js.map +1 -0
  27. package/dist/cjs/routes/auth-signout.js.map +1 -0
  28. package/dist/cjs/routes/auth-signup.js.map +1 -0
  29. package/dist/cjs/routes/auth-state.js.map +1 -0
  30. package/dist/cjs/routes/auth-update.js.map +1 -0
  31. package/dist/cjs/routes/auth-verify-email.js.map +1 -0
  32. package/dist/cjs/routes/auth.js.map +1 -0
  33. package/dist/cjs/routes/data-exists.js.map +1 -0
  34. package/dist/cjs/routes/data-export.js.map +1 -0
  35. package/dist/cjs/routes/data-get.js.map +1 -0
  36. package/dist/cjs/routes/data-import.js.map +1 -0
  37. package/dist/cjs/routes/data-index-create.js.map +1 -0
  38. package/dist/cjs/routes/data-index-delete.js.map +1 -0
  39. package/dist/cjs/routes/data-index-list.js.map +1 -0
  40. package/dist/cjs/routes/data-query.js.map +1 -0
  41. package/dist/cjs/routes/data-reflect.js +1 -1
  42. package/dist/cjs/routes/data-reflect.js.map +1 -0
  43. package/dist/cjs/routes/data-schema-get.js.map +1 -0
  44. package/dist/cjs/routes/data-schema-set.js.map +1 -0
  45. package/dist/cjs/routes/data-schema-test.js.map +1 -0
  46. package/dist/cjs/routes/data-schemas-list.js.map +1 -0
  47. package/dist/cjs/routes/data-set.js.map +1 -0
  48. package/dist/cjs/routes/data-sync-changes.js.map +1 -0
  49. package/dist/cjs/routes/data-sync-mutations.js.map +1 -0
  50. package/dist/cjs/routes/data-transaction.js.map +1 -0
  51. package/dist/cjs/routes/data-update.js.map +1 -0
  52. package/dist/cjs/routes/data.js.map +1 -0
  53. package/dist/cjs/routes/docs.js.map +1 -0
  54. package/dist/cjs/routes/meta-info.js.map +1 -0
  55. package/dist/cjs/routes/meta-logs.js.map +1 -0
  56. package/dist/cjs/routes/meta-ping.js.map +1 -0
  57. package/dist/cjs/routes/meta-stats.js.map +1 -0
  58. package/dist/cjs/routes/meta.js.map +1 -0
  59. package/dist/cjs/routes/oauth2-init.js.map +1 -0
  60. package/dist/cjs/routes/oauth2-refresh.js.map +1 -0
  61. package/dist/cjs/routes/oauth2-signin.js.map +1 -0
  62. package/dist/cjs/routes/webmanager.js.map +1 -0
  63. package/dist/cjs/rules.js +2 -9
  64. package/dist/cjs/rules.js.map +1 -0
  65. package/dist/cjs/schema/user.js.map +1 -0
  66. package/dist/cjs/server.js +1 -1
  67. package/dist/cjs/server.js.map +1 -0
  68. package/dist/cjs/settings/email.js.map +1 -0
  69. package/dist/cjs/settings/index.js +1 -1
  70. package/dist/cjs/settings/index.js.map +1 -0
  71. package/dist/cjs/shared/clients.js.map +1 -0
  72. package/dist/cjs/shared/email.js.map +1 -0
  73. package/dist/cjs/shared/env.js.map +1 -0
  74. package/dist/cjs/shared/error.js.map +1 -0
  75. package/dist/cjs/shared/http.js.map +1 -0
  76. package/dist/cjs/shared/password.js.map +1 -0
  77. package/dist/cjs/shared/rootpath.js.map +1 -0
  78. package/dist/cjs/shared/signin.js.map +1 -0
  79. package/dist/cjs/shared/simple-fetch.js.map +1 -0
  80. package/dist/cjs/shared/tokens.js.map +1 -0
  81. package/dist/cjs/shared/validate.js.map +1 -0
  82. package/dist/cjs/start.js.map +1 -0
  83. package/dist/cjs/test.js.map +1 -0
  84. package/dist/cjs/websocket/index.js.map +1 -0
  85. package/dist/cjs/websocket/manager.js +1 -1
  86. package/dist/cjs/websocket/manager.js.map +1 -0
  87. package/dist/cjs/websocket/socket.io.js.map +1 -0
  88. package/dist/esm/auth.js.map +1 -0
  89. package/dist/esm/cluster.js.map +1 -0
  90. package/dist/esm/index.d.ts +1 -1
  91. package/dist/esm/index.js.map +1 -0
  92. package/dist/esm/logger.js.map +1 -0
  93. package/dist/esm/middleware/404.js.map +1 -0
  94. package/dist/esm/middleware/admin-only.js.map +1 -0
  95. package/dist/esm/middleware/cache.js.map +1 -0
  96. package/dist/esm/middleware/connection.js.map +1 -0
  97. package/dist/esm/middleware/context.js.map +1 -0
  98. package/dist/esm/middleware/cors.js.map +1 -0
  99. package/dist/esm/middleware/swagger.js.map +1 -0
  100. package/dist/esm/middleware/user.js.map +1 -0
  101. package/dist/esm/oauth-providers/dropbox.js.map +1 -0
  102. package/dist/esm/oauth-providers/facebook.js.map +1 -0
  103. package/dist/esm/oauth-providers/google.js.map +1 -0
  104. package/dist/esm/oauth-providers/index.js.map +1 -0
  105. package/dist/esm/oauth-providers/instagram.js.map +1 -0
  106. package/dist/esm/oauth-providers/oauth-provider.js.map +1 -0
  107. package/dist/esm/oauth-providers/spotify.js.map +1 -0
  108. package/dist/esm/routes/auth-change-password.js.map +1 -0
  109. package/dist/esm/routes/auth-delete.js.map +1 -0
  110. package/dist/esm/routes/auth-forgot-password.js.map +1 -0
  111. package/dist/esm/routes/auth-reset-password.js.map +1 -0
  112. package/dist/esm/routes/auth-signin.js.map +1 -0
  113. package/dist/esm/routes/auth-signout.js.map +1 -0
  114. package/dist/esm/routes/auth-signup.js.map +1 -0
  115. package/dist/esm/routes/auth-state.js.map +1 -0
  116. package/dist/esm/routes/auth-update.js.map +1 -0
  117. package/dist/esm/routes/auth-verify-email.js.map +1 -0
  118. package/dist/esm/routes/auth.js.map +1 -0
  119. package/dist/esm/routes/data-exists.js.map +1 -0
  120. package/dist/esm/routes/data-export.js.map +1 -0
  121. package/dist/esm/routes/data-get.js.map +1 -0
  122. package/dist/esm/routes/data-import.js.map +1 -0
  123. package/dist/esm/routes/data-index-create.js.map +1 -0
  124. package/dist/esm/routes/data-index-delete.js.map +1 -0
  125. package/dist/esm/routes/data-index-list.js.map +1 -0
  126. package/dist/esm/routes/data-query.js.map +1 -0
  127. package/dist/esm/routes/data-reflect.js +1 -1
  128. package/dist/esm/routes/data-reflect.js.map +1 -0
  129. package/dist/esm/routes/data-schema-get.js.map +1 -0
  130. package/dist/esm/routes/data-schema-set.js.map +1 -0
  131. package/dist/esm/routes/data-schema-test.js.map +1 -0
  132. package/dist/esm/routes/data-schemas-list.js.map +1 -0
  133. package/dist/esm/routes/data-set.js.map +1 -0
  134. package/dist/esm/routes/data-sync-changes.js.map +1 -0
  135. package/dist/esm/routes/data-sync-mutations.js.map +1 -0
  136. package/dist/esm/routes/data-transaction.js.map +1 -0
  137. package/dist/esm/routes/data-update.js.map +1 -0
  138. package/dist/esm/routes/data.js.map +1 -0
  139. package/dist/esm/routes/docs.js.map +1 -0
  140. package/dist/esm/routes/meta-info.js.map +1 -0
  141. package/dist/esm/routes/meta-logs.js.map +1 -0
  142. package/dist/esm/routes/meta-ping.js.map +1 -0
  143. package/dist/esm/routes/meta-stats.js.map +1 -0
  144. package/dist/esm/routes/meta.js.map +1 -0
  145. package/dist/esm/routes/oauth2-init.js.map +1 -0
  146. package/dist/esm/routes/oauth2-refresh.js.map +1 -0
  147. package/dist/esm/routes/oauth2-signin.js.map +1 -0
  148. package/dist/esm/routes/webmanager.js.map +1 -0
  149. package/dist/esm/rules.js +2 -9
  150. package/dist/esm/rules.js.map +1 -0
  151. package/dist/esm/schema/user.js.map +1 -0
  152. package/dist/esm/server.js +1 -1
  153. package/dist/esm/server.js.map +1 -0
  154. package/dist/esm/settings/email.js.map +1 -0
  155. package/dist/esm/settings/index.js +1 -1
  156. package/dist/esm/settings/index.js.map +1 -0
  157. package/dist/esm/shared/clients.js.map +1 -0
  158. package/dist/esm/shared/email.js.map +1 -0
  159. package/dist/esm/shared/env.js.map +1 -0
  160. package/dist/esm/shared/error.js.map +1 -0
  161. package/dist/esm/shared/http.js.map +1 -0
  162. package/dist/esm/shared/password.js.map +1 -0
  163. package/dist/esm/shared/rootpath.js.map +1 -0
  164. package/dist/esm/shared/signin.js.map +1 -0
  165. package/dist/esm/shared/simple-fetch.js.map +1 -0
  166. package/dist/esm/shared/tokens.js.map +1 -0
  167. package/dist/esm/shared/validate.js.map +1 -0
  168. package/dist/esm/start.js.map +1 -0
  169. package/dist/esm/test.js.map +1 -0
  170. package/dist/esm/websocket/index.js.map +1 -0
  171. package/dist/esm/websocket/manager.js +1 -1
  172. package/dist/esm/websocket/manager.js.map +1 -0
  173. package/dist/esm/websocket/socket.io.js.map +1 -0
  174. package/dist/types/auth.d.ts +1 -0
  175. package/dist/types/auth.d.ts.map +1 -0
  176. package/dist/types/cluster.d.ts +1 -0
  177. package/dist/types/cluster.d.ts.map +1 -0
  178. package/dist/types/index.d.ts +1 -0
  179. package/dist/types/index.d.ts.map +1 -0
  180. package/dist/types/logger.d.ts +1 -0
  181. package/dist/types/logger.d.ts.map +1 -0
  182. package/dist/types/middleware/404.d.ts +1 -0
  183. package/dist/types/middleware/404.d.ts.map +1 -0
  184. package/dist/types/middleware/admin-only.d.ts +1 -0
  185. package/dist/types/middleware/admin-only.d.ts.map +1 -0
  186. package/dist/types/middleware/cache.d.ts +1 -0
  187. package/dist/types/middleware/cache.d.ts.map +1 -0
  188. package/dist/types/middleware/connection.d.ts +1 -0
  189. package/dist/types/middleware/connection.d.ts.map +1 -0
  190. package/dist/types/middleware/context.d.ts +1 -0
  191. package/dist/types/middleware/context.d.ts.map +1 -0
  192. package/dist/types/middleware/cors.d.ts +1 -0
  193. package/dist/types/middleware/cors.d.ts.map +1 -0
  194. package/dist/types/middleware/swagger.d.ts +1 -0
  195. package/dist/types/middleware/swagger.d.ts.map +1 -0
  196. package/dist/types/middleware/user.d.ts +1 -0
  197. package/dist/types/middleware/user.d.ts.map +1 -0
  198. package/dist/types/oauth-providers/dropbox.d.ts +1 -0
  199. package/dist/types/oauth-providers/dropbox.d.ts.map +1 -0
  200. package/dist/types/oauth-providers/facebook.d.ts +1 -0
  201. package/dist/types/oauth-providers/facebook.d.ts.map +1 -0
  202. package/dist/types/oauth-providers/google.d.ts +1 -0
  203. package/dist/types/oauth-providers/google.d.ts.map +1 -0
  204. package/dist/types/oauth-providers/index.d.ts +1 -0
  205. package/dist/types/oauth-providers/index.d.ts.map +1 -0
  206. package/dist/types/oauth-providers/instagram.d.ts +1 -0
  207. package/dist/types/oauth-providers/instagram.d.ts.map +1 -0
  208. package/dist/types/oauth-providers/oauth-provider.d.ts +1 -0
  209. package/dist/types/oauth-providers/oauth-provider.d.ts.map +1 -0
  210. package/dist/types/oauth-providers/spotify.d.ts +1 -0
  211. package/dist/types/oauth-providers/spotify.d.ts.map +1 -0
  212. package/dist/types/routes/auth-change-password.d.ts +1 -0
  213. package/dist/types/routes/auth-change-password.d.ts.map +1 -0
  214. package/dist/types/routes/auth-delete.d.ts +1 -0
  215. package/dist/types/routes/auth-delete.d.ts.map +1 -0
  216. package/dist/types/routes/auth-forgot-password.d.ts +1 -0
  217. package/dist/types/routes/auth-forgot-password.d.ts.map +1 -0
  218. package/dist/types/routes/auth-reset-password.d.ts +1 -0
  219. package/dist/types/routes/auth-reset-password.d.ts.map +1 -0
  220. package/dist/types/routes/auth-signin.d.ts +1 -0
  221. package/dist/types/routes/auth-signin.d.ts.map +1 -0
  222. package/dist/types/routes/auth-signout.d.ts +1 -0
  223. package/dist/types/routes/auth-signout.d.ts.map +1 -0
  224. package/dist/types/routes/auth-signup.d.ts +1 -0
  225. package/dist/types/routes/auth-signup.d.ts.map +1 -0
  226. package/dist/types/routes/auth-state.d.ts +1 -0
  227. package/dist/types/routes/auth-state.d.ts.map +1 -0
  228. package/dist/types/routes/auth-update.d.ts +1 -0
  229. package/dist/types/routes/auth-update.d.ts.map +1 -0
  230. package/dist/types/routes/auth-verify-email.d.ts +1 -0
  231. package/dist/types/routes/auth-verify-email.d.ts.map +1 -0
  232. package/dist/types/routes/auth.d.ts +1 -0
  233. package/dist/types/routes/auth.d.ts.map +1 -0
  234. package/dist/types/routes/data-exists.d.ts +1 -0
  235. package/dist/types/routes/data-exists.d.ts.map +1 -0
  236. package/dist/types/routes/data-export.d.ts +1 -0
  237. package/dist/types/routes/data-export.d.ts.map +1 -0
  238. package/dist/types/routes/data-get.d.ts +3 -2
  239. package/dist/types/routes/data-get.d.ts.map +1 -0
  240. package/dist/types/routes/data-import.d.ts +1 -0
  241. package/dist/types/routes/data-import.d.ts.map +1 -0
  242. package/dist/types/routes/data-index-create.d.ts +1 -0
  243. package/dist/types/routes/data-index-create.d.ts.map +1 -0
  244. package/dist/types/routes/data-index-delete.d.ts +1 -0
  245. package/dist/types/routes/data-index-delete.d.ts.map +1 -0
  246. package/dist/types/routes/data-index-list.d.ts +1 -0
  247. package/dist/types/routes/data-index-list.d.ts.map +1 -0
  248. package/dist/types/routes/data-query.d.ts +1 -0
  249. package/dist/types/routes/data-query.d.ts.map +1 -0
  250. package/dist/types/routes/data-reflect.d.ts +1 -0
  251. package/dist/types/routes/data-reflect.d.ts.map +1 -0
  252. package/dist/types/routes/data-schema-get.d.ts +1 -0
  253. package/dist/types/routes/data-schema-get.d.ts.map +1 -0
  254. package/dist/types/routes/data-schema-set.d.ts +2 -1
  255. package/dist/types/routes/data-schema-set.d.ts.map +1 -0
  256. package/dist/types/routes/data-schema-test.d.ts +3 -4
  257. package/dist/types/routes/data-schema-test.d.ts.map +1 -0
  258. package/dist/types/routes/data-schemas-list.d.ts +1 -0
  259. package/dist/types/routes/data-schemas-list.d.ts.map +1 -0
  260. package/dist/types/routes/data-set.d.ts +3 -2
  261. package/dist/types/routes/data-set.d.ts.map +1 -0
  262. package/dist/types/routes/data-sync-changes.d.ts +2 -1
  263. package/dist/types/routes/data-sync-changes.d.ts.map +1 -0
  264. package/dist/types/routes/data-sync-mutations.d.ts +2 -1
  265. package/dist/types/routes/data-sync-mutations.d.ts.map +1 -0
  266. package/dist/types/routes/data-transaction.d.ts +3 -2
  267. package/dist/types/routes/data-transaction.d.ts.map +1 -0
  268. package/dist/types/routes/data-update.d.ts +3 -2
  269. package/dist/types/routes/data-update.d.ts.map +1 -0
  270. package/dist/types/routes/data.d.ts +1 -0
  271. package/dist/types/routes/data.d.ts.map +1 -0
  272. package/dist/types/routes/docs.d.ts +1 -0
  273. package/dist/types/routes/docs.d.ts.map +1 -0
  274. package/dist/types/routes/meta-info.d.ts +1 -0
  275. package/dist/types/routes/meta-info.d.ts.map +1 -0
  276. package/dist/types/routes/meta-logs.d.ts +2 -1
  277. package/dist/types/routes/meta-logs.d.ts.map +1 -0
  278. package/dist/types/routes/meta-ping.d.ts +1 -0
  279. package/dist/types/routes/meta-ping.d.ts.map +1 -0
  280. package/dist/types/routes/meta-stats.d.ts +1 -0
  281. package/dist/types/routes/meta-stats.d.ts.map +1 -0
  282. package/dist/types/routes/meta.d.ts +1 -0
  283. package/dist/types/routes/meta.d.ts.map +1 -0
  284. package/dist/types/routes/oauth2-init.d.ts +1 -0
  285. package/dist/types/routes/oauth2-init.d.ts.map +1 -0
  286. package/dist/types/routes/oauth2-refresh.d.ts +1 -0
  287. package/dist/types/routes/oauth2-refresh.d.ts.map +1 -0
  288. package/dist/types/routes/oauth2-signin.d.ts +1 -0
  289. package/dist/types/routes/oauth2-signin.d.ts.map +1 -0
  290. package/dist/types/routes/webmanager.d.ts +1 -0
  291. package/dist/types/routes/webmanager.d.ts.map +1 -0
  292. package/dist/types/rules.d.ts +1 -7
  293. package/dist/types/rules.d.ts.map +1 -0
  294. package/dist/types/schema/user.d.ts +1 -0
  295. package/dist/types/schema/user.d.ts.map +1 -0
  296. package/dist/types/server.d.ts +1 -0
  297. package/dist/types/server.d.ts.map +1 -0
  298. package/dist/types/settings/email.d.ts +1 -0
  299. package/dist/types/settings/email.d.ts.map +1 -0
  300. package/dist/types/settings/index.d.ts +2 -1
  301. package/dist/types/settings/index.d.ts.map +1 -0
  302. package/dist/types/shared/clients.d.ts +4 -3
  303. package/dist/types/shared/clients.d.ts.map +1 -0
  304. package/dist/types/shared/email.d.ts +1 -0
  305. package/dist/types/shared/email.d.ts.map +1 -0
  306. package/dist/types/shared/env.d.ts +2 -2
  307. package/dist/types/shared/env.d.ts.map +1 -0
  308. package/dist/types/shared/error.d.ts +1 -0
  309. package/dist/types/shared/error.d.ts.map +1 -0
  310. package/dist/types/shared/http.d.ts +1 -0
  311. package/dist/types/shared/http.d.ts.map +1 -0
  312. package/dist/types/shared/password.d.ts +1 -0
  313. package/dist/types/shared/password.d.ts.map +1 -0
  314. package/dist/types/shared/rootpath.d.ts +1 -0
  315. package/dist/types/shared/rootpath.d.ts.map +1 -0
  316. package/dist/types/shared/signin.d.ts +1 -0
  317. package/dist/types/shared/signin.d.ts.map +1 -0
  318. package/dist/types/shared/simple-fetch.d.ts +1 -0
  319. package/dist/types/shared/simple-fetch.d.ts.map +1 -0
  320. package/dist/types/shared/tokens.d.ts +1 -0
  321. package/dist/types/shared/tokens.d.ts.map +1 -0
  322. package/dist/types/shared/validate.d.ts +1 -0
  323. package/dist/types/shared/validate.d.ts.map +1 -0
  324. package/dist/types/start.d.ts +1 -0
  325. package/dist/types/start.d.ts.map +1 -0
  326. package/dist/types/test.d.ts +1 -0
  327. package/dist/types/test.d.ts.map +1 -0
  328. package/dist/types/websocket/index.d.ts +1 -0
  329. package/dist/types/websocket/index.d.ts.map +1 -0
  330. package/dist/types/websocket/manager.d.ts +11 -10
  331. package/dist/types/websocket/manager.d.ts.map +1 -0
  332. package/dist/types/websocket/socket.io.d.ts +1 -0
  333. package/dist/types/websocket/socket.io.d.ts.map +1 -0
  334. package/package.json +6 -5
  335. package/src/auth.ts +87 -0
  336. package/src/cluster.ts +62 -0
  337. package/src/index.ts +4 -0
  338. package/src/logger.ts +56 -0
  339. package/src/middleware/404.ts +13 -0
  340. package/src/middleware/admin-only.ts +29 -0
  341. package/src/middleware/cache.ts +15 -0
  342. package/src/middleware/connection.ts +48 -0
  343. package/src/middleware/context.ts +23 -0
  344. package/src/middleware/cors.ts +49 -0
  345. package/src/middleware/swagger.ts +19 -0
  346. package/src/middleware/user.ts +51 -0
  347. package/src/oauth-providers/dropbox.ts +144 -0
  348. package/src/oauth-providers/facebook.ts +103 -0
  349. package/src/oauth-providers/google.ts +147 -0
  350. package/src/oauth-providers/index.ts +21 -0
  351. package/src/oauth-providers/instagram.ts +98 -0
  352. package/src/oauth-providers/oauth-provider.ts +65 -0
  353. package/src/oauth-providers/spotify.ts +127 -0
  354. package/src/placeholder.d.ts +12 -0
  355. package/src/routes/auth-change-password.ts +92 -0
  356. package/src/routes/auth-change-password.yaml +74 -0
  357. package/src/routes/auth-delete.ts +49 -0
  358. package/src/routes/auth-delete.yaml +78 -0
  359. package/src/routes/auth-forgot-password.ts +77 -0
  360. package/src/routes/auth-forgot-password.yaml +50 -0
  361. package/src/routes/auth-reset-password.ts +96 -0
  362. package/src/routes/auth-reset-password.yaml +54 -0
  363. package/src/routes/auth-signin.ts +55 -0
  364. package/src/routes/auth-signin.yaml +130 -0
  365. package/src/routes/auth-signout.ts +64 -0
  366. package/src/routes/auth-signout.yaml +46 -0
  367. package/src/routes/auth-signup.ts +164 -0
  368. package/src/routes/auth-signup.yaml +136 -0
  369. package/src/routes/auth-state.ts +20 -0
  370. package/src/routes/auth-state.yaml +29 -0
  371. package/src/routes/auth-update.ts +149 -0
  372. package/src/routes/auth-update.yaml +152 -0
  373. package/src/routes/auth-verify-email.ts +75 -0
  374. package/src/routes/auth-verify-email.yaml +53 -0
  375. package/src/routes/auth.ts +67 -0
  376. package/src/routes/data-exists.ts +31 -0
  377. package/src/routes/data-exists.yaml +44 -0
  378. package/src/routes/data-export.ts +51 -0
  379. package/src/routes/data-export.yaml +64 -0
  380. package/src/routes/data-get.ts +67 -0
  381. package/src/routes/data-get.yaml +54 -0
  382. package/src/routes/data-import.ts +56 -0
  383. package/src/routes/data-import.yaml +75 -0
  384. package/src/routes/data-index-create.ts +82 -0
  385. package/src/routes/data-index-create.yaml +105 -0
  386. package/src/routes/data-index-delete.ts +36 -0
  387. package/src/routes/data-index-delete.yaml +51 -0
  388. package/src/routes/data-index-list.ts +39 -0
  389. package/src/routes/data-index-list.yaml +84 -0
  390. package/src/routes/data-query.ts +97 -0
  391. package/src/routes/data-query.yaml +166 -0
  392. package/src/routes/data-reflect.ts +91 -0
  393. package/src/routes/data-reflect.yaml +124 -0
  394. package/src/routes/data-schema-get.ts +36 -0
  395. package/src/routes/data-schema-get.yaml +53 -0
  396. package/src/routes/data-schema-set.ts +35 -0
  397. package/src/routes/data-schema-set.yaml +60 -0
  398. package/src/routes/data-schema-test.ts +48 -0
  399. package/src/routes/data-schema-test.yaml +66 -0
  400. package/src/routes/data-schemas-list.ts +31 -0
  401. package/src/routes/data-schemas-list.yaml +41 -0
  402. package/src/routes/data-set.ts +83 -0
  403. package/src/routes/data-set.yaml +77 -0
  404. package/src/routes/data-sync-changes.ts +77 -0
  405. package/src/routes/data-sync-changes.yaml +67 -0
  406. package/src/routes/data-sync-mutations.ts +77 -0
  407. package/src/routes/data-sync-mutations.yaml +67 -0
  408. package/src/routes/data-transaction-finish.yaml +82 -0
  409. package/src/routes/data-transaction-start.yaml +58 -0
  410. package/src/routes/data-transaction.ts +166 -0
  411. package/src/routes/data-update.ts +84 -0
  412. package/src/routes/data-update.yaml +77 -0
  413. package/src/routes/data.ts +79 -0
  414. package/src/routes/docs.ts +249 -0
  415. package/src/routes/meta-info.ts +80 -0
  416. package/src/routes/meta-info.yaml +41 -0
  417. package/src/routes/meta-logs.ts +57 -0
  418. package/src/routes/meta-ping.ts +15 -0
  419. package/src/routes/meta-ping.yaml +23 -0
  420. package/src/routes/meta-stats.ts +31 -0
  421. package/src/routes/meta-stats.yaml +41 -0
  422. package/src/routes/meta.ts +22 -0
  423. package/src/routes/oauth2-init.ts +44 -0
  424. package/src/routes/oauth2-init.yaml +63 -0
  425. package/src/routes/oauth2-refresh.ts +39 -0
  426. package/src/routes/oauth2-refresh.yaml +65 -0
  427. package/src/routes/oauth2-signin.ts +286 -0
  428. package/src/routes/oauth2-signin.yaml +66 -0
  429. package/src/routes/webmanager.ts +29 -0
  430. package/src/rules.ts +189 -0
  431. package/src/schema/user.ts +99 -0
  432. package/src/server.ts +419 -0
  433. package/src/settings/email.ts +18 -0
  434. package/src/settings/index.ts +241 -0
  435. package/src/shared/clients.ts +31 -0
  436. package/src/shared/email.ts +33 -0
  437. package/src/shared/env.ts +38 -0
  438. package/src/shared/error.ts +37 -0
  439. package/src/shared/http.ts +26 -0
  440. package/src/shared/password.ts +41 -0
  441. package/src/shared/rootpath.ts +17 -0
  442. package/src/shared/signin.ts +149 -0
  443. package/src/shared/simple-fetch.ts +65 -0
  444. package/src/shared/tokens.ts +77 -0
  445. package/src/shared/validate.ts +53 -0
  446. package/src/start.ts +48 -0
  447. package/src/test.ts +10 -0
  448. package/src/websocket/index.ts +336 -0
  449. package/src/websocket/manager.ts +46 -0
  450. package/src/websocket/socket.io.ts +90 -0
  451. package/tsconfig-cjs.json +11 -0
  452. package/tsconfig.json +22 -0
@@ -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 by adding the access token as auth_token query parameter
14
+ if (req.path.startsWith('/export/') || req.path.startsWith('/logs')) {
15
+ // For now, only allow '/export' or '/logs' api calls
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: 'internal', 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
+ };
@@ -0,0 +1,144 @@
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
+
4
+ /**
5
+ * Details of your app to access the Dropbox API
6
+ */
7
+ export interface IDropboxAuthSettings extends IOAuth2ProviderSettings {
8
+ /** specify specific scopes, or leave empty to get all configured scopes for the app. 'account_info.read' will be added automatically if you provided other scopes. See permissions tab in your Dropbox app settings */
9
+ scopes?: string[]
10
+ }
11
+
12
+ interface IDropboxAuthToken { access_token: string, expires_in: number, expires: Date, refresh_token: string, scope: string, token_type: string, account_id: string, uid: string }
13
+ interface IDropboxError { code: number, message?: string, error?: { ".tag": string }, error_summary?: string, user_message?: string }
14
+ interface IDropboxUser {
15
+ account_id: string
16
+ name: {
17
+ given_name: string
18
+ surname: string
19
+ familiar_name: string
20
+ display_name: string
21
+ abbreviated_name: string
22
+ }
23
+ email: string
24
+ email_verified: boolean
25
+ disabled: boolean
26
+ locale: string
27
+ referral_link: string
28
+ is_paired: boolean
29
+ account_type: {
30
+ ".tag": "basic"|"pro"|"business"
31
+ }
32
+ root_info: {
33
+ ".tag": "user"
34
+ root_namespace_id: string
35
+ home_namespace_id: string
36
+ }
37
+ profile_photo_url?: string
38
+ country: string
39
+ team?: {
40
+ id: string
41
+ name: string
42
+ sharing_policies: {
43
+ shared_folder_member_policy: { ".tag": "team"|"anyone" }
44
+ shared_folder_join_policy: { ".tag": "from_team_only"|"from_anyone" }
45
+ shared_link_create_policy: { ".tag": "default_public"|"default_team_only"|"team_only" }
46
+ }
47
+ office_addin_policy: { ".tag": "enabled"|"disabled" }
48
+ }
49
+ team_member_id?: string
50
+ }
51
+ export class DropboxAuthProvider extends OAuth2Provider {
52
+
53
+ constructor(settings: IDropboxAuthSettings) {
54
+ super(settings);
55
+ if (!settings.scopes) { settings.scopes = []; }
56
+ if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) { settings.scopes.push('account_info.read'); }
57
+ }
58
+
59
+ /**
60
+ * Starts auth flow by getting the url the user should be redirected to
61
+ * @param info.redirectUrl Url dropbox will redirect to after authorizing
62
+ * @param info.state Optional state that will be passed to redirectUri by dropbox
63
+ * @param info.options Optional Dropbox specific authentication settings
64
+ * @param info.options.require_role If this parameter is specified, the user will be asked to authorize with a particular type of Dropbox account, either work for a team account or personal for a personal account. Your app should still verify the type of Dropbox account after authorization since the user could modify or remove the require_role parameter.
65
+ * @param info.options.force_reapprove Whether or not to force the user to approve the app again if they've already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.
66
+ * @param info.options.disable_signup When true (default is false) users will not be able to sign up for a Dropbox account via the authorization page. Instead, the authorization page will show a link to the Dropbox iOS app in the App Store. This is only intended for use when necessary for compliance with App Store policies.
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.
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.
69
+ */
70
+ async init(info: OAuth2ProviderInitInfo) {
71
+ // Return url to get authorization code with
72
+ const options = info.options || {};
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)}`;
74
+ return authUrl;
75
+ }
76
+
77
+ getAccessToken(params: IOAuth2AuthCodeParams|IOAuth2RefreshTokenParams) {
78
+ // Request access & refresh tokens with authorization code
79
+ return fetch('https://api.dropbox.com/oauth2/token', {
80
+ method: 'POST',
81
+ headers: {
82
+ "Content-Type": "application/x-www-form-urlencoded"
83
+ },
84
+ body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
85
+ (params.type === 'refresh'
86
+ ? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
87
+ : `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`)
88
+ })
89
+ .then(async response => {
90
+ if (response.status !== 200) {
91
+ // Handle error
92
+ const code = response.status;
93
+ const hasJSON = response.headers.get('Content-Type') === 'application/json';
94
+ const details = await (hasJSON ? response.json() : response.text());
95
+ throw new Error(`${code}: ${hasJSON ? details.error_description ? `${details.error}, ${details.error_description}` : (details as IDropboxError).error_summary : details}`);
96
+ }
97
+ const result:IDropboxAuthToken = await response.json();
98
+ const secondsToExpiry = result.expires_in;
99
+ result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
100
+ return result;
101
+ });
102
+ }
103
+
104
+ getUserInfo(access_token: string) {
105
+ return fetch(`https://api.dropboxapi.com/2/users/get_current_account`, {
106
+ method: 'POST',
107
+ headers: {
108
+ 'Authorization': `Bearer ${access_token}`
109
+ }
110
+ })
111
+ .then(async response => {
112
+ if (response.status !== 200) {
113
+ const code = response.status;
114
+ const hasJSON = response.headers.get('Content-Type') === 'application/json';
115
+ const details = await (hasJSON ? response.json() : response.text());
116
+ throw new Error(`${code}: ${hasJSON ? (details as IDropboxError).error_summary : details}`);
117
+ }
118
+ const result = await response.json();
119
+ const user = result as IDropboxUser;
120
+ return {
121
+ id: user.account_id,
122
+ name: `${user.name.given_name} ${user.name.surname}`,
123
+ display_name: user.name.display_name,
124
+ picture: user.profile_photo_url ? [{ url: user.profile_photo_url }] : null,
125
+ email: user.email,
126
+ email_verified: user.email_verified,
127
+ other: {
128
+ account_type: user.account_type['.tag'],
129
+ disabled: user.disabled,
130
+ locale: user.locale,
131
+ country: user.country,
132
+ // include the following?
133
+ // referral_link: user.referral_link,
134
+ // team_id: user.team.id,
135
+ // team_name: user.team.name,
136
+ // team_member_id: user.team_member_id
137
+ }
138
+ };
139
+ });
140
+ }
141
+
142
+ }
143
+
144
+ export const AuthProvider = DropboxAuthProvider;
@@ -0,0 +1,103 @@
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
+
4
+ /**
5
+ * Details of your app to access the Facebook Graph API
6
+ */
7
+ export interface IFacebookAuthSettings extends IOAuth2ProviderSettings {
8
+ /** 'email' and additional scopes you want to access. See https://developers.facebook.com/docs/facebook-login/permissions/ */
9
+ scopes?: string[]
10
+ }
11
+
12
+ interface IFacebookAuthToken { access_token: string, expires_in: number, expires: Date, refresh_token: string, scope: string, token_type: string }
13
+ interface IFacebookError { code: number, message: string, type: string, fbtrace_id: string }
14
+ interface IFacebookUser {
15
+ id: string
16
+ email: string
17
+ name: string
18
+ first_name: string
19
+ middle_name: string
20
+ last_name: string
21
+ short_name: string
22
+ picture: {
23
+ data: {
24
+ height: number,
25
+ is_silhouette: boolean,
26
+ url: string,
27
+ width: number
28
+ }
29
+ }
30
+ }
31
+ export class FacebookAuthProvider extends OAuth2Provider {
32
+
33
+ constructor(settings: IFacebookAuthSettings) {
34
+ super(settings);
35
+ if (!settings.scopes) { settings.scopes = []; }
36
+ if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
37
+ }
38
+
39
+ /**
40
+ * Starts auth flow by getting the url the user should be redirected to
41
+ * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
42
+ * @param info.state Optional state that will be passed to redirectUri by spotify
43
+ */
44
+ async init(info: OAuth2ProviderInitInfo) {
45
+ // Return url to get authorization code with
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)}`;
47
+ return authUrl;
48
+ }
49
+
50
+ getAccessToken(params: IOAuth2AuthCodeParams|IOAuth2RefreshTokenParams) {
51
+ // Request access token with authorization code, or previously granted (short or long-lived) access_token
52
+ const url = `https://graph.facebook.com/v7.0/oauth/access_token?client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
53
+ (params.type === 'refresh'
54
+ ? `&grant_type=fb_exchange_token&fb_exchange_token=${params.refresh_token}`
55
+ : `&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`)
56
+ return fetch(url)
57
+ .then(response => response.json())
58
+ .then((result: IFacebookAuthToken) => {
59
+ if ((result as any).error) {
60
+ const error = (result as any).error as IFacebookError
61
+ throw new Error(`${error.type} ${error.code}: ${error.message}`);
62
+ }
63
+ const secondsToExpiry = result.expires_in;
64
+ result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
65
+
66
+ // A short-lived access token can be exchanged for a long-lived (60 day) token.
67
+ // Not sure if a long-lived token can be used to get a new long-lived token,
68
+ // needs testing. See docs at: https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing/
69
+ result.refresh_token = result.access_token;
70
+ return result;
71
+ });
72
+ }
73
+
74
+ getUserInfo(access_token: string) {
75
+ // TODO: Check if any requested scopes have not been granted access
76
+ // await fetch(`https://graph.facebook.com/v7.0/me/permissions`);
77
+
78
+ return fetch(`https://graph.facebook.com/v7.0/me?fields=email,name,short_name,picture&access_token=${access_token}`)
79
+ .then(async response => {
80
+ const result = await response.json();
81
+ if (response.status !== 200) {
82
+ const error = result as IFacebookError;
83
+ throw new Error(`${error.code}: ${error.message}`);
84
+ }
85
+
86
+ const user = result as IFacebookUser;
87
+ return {
88
+ id: user.id,
89
+ name: user.name,
90
+ display_name: user.short_name,
91
+ picture: user.picture.data.is_silhouette ? null : [{ width: user.picture.data.width, height: user.picture.data.height, url: user.picture.data.url }],
92
+ email: user.email,
93
+ email_verified: typeof user.email === 'string', // If we get the email address, it's always verified
94
+ other: {
95
+ // We haven't requested more, so we didn't get more
96
+ }
97
+ };
98
+ });
99
+ }
100
+
101
+ }
102
+
103
+ export const AuthProvider = FacebookAuthProvider;
@@ -0,0 +1,147 @@
1
+ import { IOAuth2ProviderSettings, IOpenIDToken, IOpenIDConfiguration, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2ProviderInitInfo, OAuth2Provider } from "./oauth-provider";
2
+ import { fetch } from '../shared/simple-fetch';
3
+
4
+ /**
5
+ * Details of your app to access the Google API. See https://developers.google.com/identity/protocols/oauth2/scopes
6
+ */
7
+ export interface IGoogleAuthSettings extends IOAuth2ProviderSettings {
8
+ /** 'openid', 'email', 'profile' and additional scopes you want to access. */
9
+ scopes?: string[]
10
+ }
11
+
12
+ interface IGoogleAuthToken { access_token: string, expires_in: number, expires: Date, id_token: IOpenIDToken, refresh_token: string, scope: string, token_type: string }
13
+ interface IGoogleError { error: string, error_description: string }
14
+ interface IGoogleUser {
15
+ // See https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
16
+ sub: string // "subject"
17
+ name: string // full name
18
+ given_name: string // first name
19
+ family_name: string // last name
20
+ middle_name: string
21
+ nickname: string
22
+ preferred_username: string
23
+ profile: string // url
24
+ picture: string // url
25
+ website: string // url
26
+ email: string
27
+ email_verified: boolean
28
+ gender: string
29
+ birthdate: string // YYYY-MM-DD
30
+ zoneinfo: string // timezone location (eg Europe/Paris)
31
+ locale: string // eg en-us, nl-be
32
+ phone_number: string
33
+ phone_number_verified: boolean
34
+ address: {
35
+ // See https://openid.net/specs/openid-connect-core-1_0.html#AddressClaim
36
+ formatted?: string
37
+ street_address: string
38
+ locality: string // eg city
39
+ region: string // State, province, prefecture, or region component
40
+ postal_code: string
41
+ country: string
42
+ }
43
+ updated_at: number
44
+ }
45
+
46
+ export class GoogleAuthProvider extends OAuth2Provider {
47
+
48
+ _config: IOpenIDConfiguration
49
+
50
+ constructor(settings: IGoogleAuthSettings) {
51
+ super(settings);
52
+ if (!settings.scopes) { settings.scopes = []; }
53
+ if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
54
+ if (!settings.scopes.includes('profile')) { settings.scopes.push('profile'); }
55
+ if (!settings.scopes.includes('openid')) { settings.scopes.push('openid'); }
56
+ }
57
+
58
+ async getOpenIDConfig() {
59
+ // Get Open ID config ("The Discovery document")
60
+ if (this._config) { return this._config; }
61
+ this._config = await fetch(`https://accounts.google.com/.well-known/openid-configuration`).then(res => res.json());
62
+ return this._config;
63
+ }
64
+
65
+ /**
66
+ * Starts auth flow by getting the url the user should be redirected to
67
+ * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
68
+ * @param info.state Optional state that will be passed to redirectUri by spotify
69
+ */
70
+ async init(info: OAuth2ProviderInitInfo) {
71
+ // Return url to get authorization code with
72
+ // See https://developers.google.com/identity/protocols/oauth2/web-server#httprest
73
+
74
+ const config = await this.getOpenIDConfig();
75
+ // https://accounts.google.com/o/oauth2/v2/auth
76
+ const authUrl = `${config.authorization_endpoint}?response_type=code&access_type=offline&include_granted_scopes=true&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
77
+ // optional: login_hint=email@server.com
78
+ // optional: prompt=none|consent|select_account
79
+ return authUrl;
80
+ }
81
+
82
+ async getAccessToken(params: IOAuth2AuthCodeParams|IOAuth2RefreshTokenParams) : Promise<IGoogleAuthToken> {
83
+ // Request access & refresh tokens with authorization code, or refresh token
84
+ const config = await this.getOpenIDConfig();
85
+ // 'https://oauth2.googleapis.com/token'
86
+ return fetch(config.token_endpoint, {
87
+ method: 'POST',
88
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
89
+ body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}&code=`
90
+ + (params.type === 'refresh'
91
+ ? `${params.refresh_token}&grant_type=refresh_token`
92
+ : `${params.auth_code}&grant_type=authorization_code&redirect_uri=${encodeURIComponent(params.redirect_url)}`)
93
+ })
94
+ .then(response => response.json())
95
+ .then((result: IGoogleAuthToken) => {
96
+ if ((result as any).error) {
97
+ throw new Error((result as any).error);
98
+ }
99
+ const secondsToExpiry = result.expires_in;
100
+ result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
101
+ return result;
102
+ });
103
+ }
104
+
105
+ async revokeAccess(access_token: string) {
106
+ const config = await this.getOpenIDConfig();
107
+ // https://oauth2.googleapis.com/revoke
108
+ return fetch(`${config.revocation_endpoint}?token=${access_token}`)
109
+ .then(response => {
110
+ if (response.status !== 200) {
111
+ throw new Error(`Revoke failed, error ${response.status}`);
112
+ }
113
+ });
114
+ }
115
+
116
+ async getUserInfo(access_token: string) {
117
+ const config = await this.getOpenIDConfig();
118
+ // https://openidconnect.googleapis.com/v1/userinfo
119
+ return fetch(config.userinfo_endpoint, {
120
+ method: 'GET' ,
121
+ headers: { 'Authorization': `Bearer ${access_token}` }
122
+ })
123
+ .then(async response => {
124
+ const result = await response.json();
125
+ if (response.status !== 200) {
126
+ const error = result as IGoogleError;
127
+ throw new Error(`${error.error}: ${error.error_description}`);
128
+ }
129
+
130
+ const user = result as IGoogleUser;
131
+ return {
132
+ id: user.sub,
133
+ name: user.name,
134
+ display_name: user.nickname || user.given_name,
135
+ picture: user.picture ? [{ url: user.picture }] : [],
136
+ email: user.email,
137
+ email_verified: user.email_verified,
138
+ other: Object.keys(user)
139
+ .filter(key => !['sub','name','picture','email','email_verified'].includes(key))
140
+ .reduce((obj, key) => { obj[key] = user[key]; return obj; }, {})
141
+ };
142
+ });
143
+ }
144
+
145
+ }
146
+
147
+ export const AuthProvider = GoogleAuthProvider;
@@ -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;