prostgles-server 4.2.187 → 4.2.188

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 (338) hide show
  1. package/.eslintignore +2 -1
  2. package/.eslintrc.json +2 -0
  3. package/dist/Auth/AuthHandler.d.ts +18 -11
  4. package/dist/Auth/AuthHandler.d.ts.map +1 -1
  5. package/dist/Auth/AuthHandler.js +94 -120
  6. package/dist/Auth/AuthHandler.js.map +1 -1
  7. package/dist/Auth/AuthTypes.d.ts +78 -71
  8. package/dist/Auth/AuthTypes.d.ts.map +1 -1
  9. package/dist/Auth/{setEmailProvider.d.ts → authProviders/setEmailProvider.d.ts} +1 -1
  10. package/dist/Auth/authProviders/setEmailProvider.d.ts.map +1 -0
  11. package/dist/Auth/authProviders/setEmailProvider.js +27 -0
  12. package/dist/Auth/authProviders/setEmailProvider.js.map +1 -0
  13. package/dist/Auth/authProviders/setOAuthProviders.d.ts +5 -0
  14. package/dist/Auth/authProviders/setOAuthProviders.d.ts.map +1 -0
  15. package/dist/Auth/authProviders/setOAuthProviders.js +78 -0
  16. package/dist/Auth/authProviders/setOAuthProviders.js.map +1 -0
  17. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts +7 -0
  18. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts.map +1 -0
  19. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js +29 -0
  20. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js.map +1 -0
  21. package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts +7 -0
  22. package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts.map +1 -0
  23. package/dist/Auth/endpoints/getRegisterRequestHandler.js +74 -0
  24. package/dist/Auth/endpoints/getRegisterRequestHandler.js.map +1 -0
  25. package/dist/Auth/setAuthProviders.d.ts.map +1 -1
  26. package/dist/Auth/setAuthProviders.js +4 -74
  27. package/dist/Auth/setAuthProviders.js.map +1 -1
  28. package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
  29. package/dist/Auth/setupAuthRoutes.js +23 -33
  30. package/dist/Auth/setupAuthRoutes.js.map +1 -1
  31. package/dist/Auth/utils/checkDmarc.d.ts +2 -0
  32. package/dist/Auth/utils/checkDmarc.d.ts.map +1 -0
  33. package/dist/Auth/utils/checkDmarc.js +22 -0
  34. package/dist/Auth/utils/checkDmarc.js.map +1 -0
  35. package/dist/Auth/utils/getClientRequestIPsInfo.d.ts +3 -0
  36. package/dist/Auth/utils/getClientRequestIPsInfo.d.ts.map +1 -0
  37. package/dist/Auth/utils/getClientRequestIPsInfo.js +29 -0
  38. package/dist/Auth/utils/getClientRequestIPsInfo.js.map +1 -0
  39. package/dist/Auth/utils/getReturnUrl.d.ts +3 -0
  40. package/dist/Auth/utils/getReturnUrl.d.ts.map +1 -0
  41. package/dist/Auth/utils/getReturnUrl.js +15 -0
  42. package/dist/Auth/utils/getReturnUrl.js.map +1 -0
  43. package/dist/Auth/utils/getSafeReturnURL.d.ts.map +1 -0
  44. package/dist/Auth/utils/getSafeReturnURL.js.map +1 -0
  45. package/dist/DBEventsManager.d.ts.map +1 -1
  46. package/dist/DBEventsManager.js +4 -5
  47. package/dist/DBEventsManager.js.map +1 -1
  48. package/dist/DBSchemaBuilder.js +1 -1
  49. package/dist/DBSchemaBuilder.js.map +1 -1
  50. package/dist/DboBuilder/DboBuilder.d.ts +0 -1
  51. package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
  52. package/dist/DboBuilder/DboBuilder.js +3 -12
  53. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  54. package/dist/DboBuilder/DboBuilderTypes.d.ts +4 -4
  55. package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
  56. package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
  57. package/dist/DboBuilder/QueryBuilder/Functions.d.ts.map +1 -1
  58. package/dist/DboBuilder/QueryBuilder/Functions.js +38 -76
  59. package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
  60. package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
  61. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +4 -12
  62. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
  63. package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts.map +1 -1
  64. package/dist/DboBuilder/QueryBuilder/getNewQuery.js +23 -33
  65. package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
  66. package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts +1 -1
  67. package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts.map +1 -1
  68. package/dist/DboBuilder/QueryBuilder/getSelectQuery.js +6 -6
  69. package/dist/DboBuilder/QueryBuilder/getSelectQuery.js.map +1 -1
  70. package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
  71. package/dist/DboBuilder/QueryStreamer.js +13 -19
  72. package/dist/DboBuilder/QueryStreamer.js.map +1 -1
  73. package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
  74. package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
  75. package/dist/DboBuilder/TableHandler/DataValidator.js +7 -16
  76. package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
  77. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  78. package/dist/DboBuilder/TableHandler/TableHandler.js +7 -5
  79. package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
  80. package/dist/DboBuilder/TableHandler/delete.d.ts.map +1 -1
  81. package/dist/DboBuilder/TableHandler/delete.js +5 -8
  82. package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
  83. package/dist/DboBuilder/TableHandler/insert.d.ts.map +1 -1
  84. package/dist/DboBuilder/TableHandler/insert.js +10 -15
  85. package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
  86. package/dist/DboBuilder/TableHandler/insertTest.js +1 -1
  87. package/dist/DboBuilder/TableHandler/insertTest.js.map +1 -1
  88. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts.map +1 -1
  89. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js +1 -1
  90. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js.map +1 -1
  91. package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
  92. package/dist/DboBuilder/TableHandler/update.js +5 -9
  93. package/dist/DboBuilder/TableHandler/update.js.map +1 -1
  94. package/dist/DboBuilder/TableHandler/updateFile.d.ts +1 -1
  95. package/dist/DboBuilder/TableHandler/updateFile.d.ts.map +1 -1
  96. package/dist/DboBuilder/TableHandler/updateFile.js +7 -9
  97. package/dist/DboBuilder/TableHandler/updateFile.js.map +1 -1
  98. package/dist/DboBuilder/TableHandler/upsert.d.ts.map +1 -1
  99. package/dist/DboBuilder/TableHandler/upsert.js +1 -1
  100. package/dist/DboBuilder/TableHandler/upsert.js.map +1 -1
  101. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  102. package/dist/DboBuilder/ViewHandler/ViewHandler.js +11 -13
  103. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  104. package/dist/DboBuilder/ViewHandler/count.js +1 -1
  105. package/dist/DboBuilder/ViewHandler/count.js.map +1 -1
  106. package/dist/DboBuilder/ViewHandler/find.d.ts.map +1 -1
  107. package/dist/DboBuilder/ViewHandler/find.js +20 -27
  108. package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
  109. package/dist/DboBuilder/ViewHandler/getExistsCondition.d.ts.map +1 -1
  110. package/dist/DboBuilder/ViewHandler/getExistsCondition.js +4 -10
  111. package/dist/DboBuilder/ViewHandler/getExistsCondition.js.map +1 -1
  112. package/dist/DboBuilder/ViewHandler/getInfo.js +2 -2
  113. package/dist/DboBuilder/ViewHandler/getInfo.js.map +1 -1
  114. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts.map +1 -1
  115. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js +6 -22
  116. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js.map +1 -1
  117. package/dist/DboBuilder/ViewHandler/parseFieldFilter.d.ts.map +1 -1
  118. package/dist/DboBuilder/ViewHandler/parseFieldFilter.js +6 -10
  119. package/dist/DboBuilder/ViewHandler/parseFieldFilter.js.map +1 -1
  120. package/dist/DboBuilder/ViewHandler/parseJoinPath.d.ts.map +1 -1
  121. package/dist/DboBuilder/ViewHandler/parseJoinPath.js +8 -11
  122. package/dist/DboBuilder/ViewHandler/parseJoinPath.js.map +1 -1
  123. package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts.map +1 -1
  124. package/dist/DboBuilder/ViewHandler/prepareSortItems.js +7 -12
  125. package/dist/DboBuilder/ViewHandler/prepareSortItems.js.map +1 -1
  126. package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts.map +1 -1
  127. package/dist/DboBuilder/ViewHandler/prepareWhere.js +6 -10
  128. package/dist/DboBuilder/ViewHandler/prepareWhere.js.map +1 -1
  129. package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
  130. package/dist/DboBuilder/dboBuilderUtils.js +8 -23
  131. package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
  132. package/dist/DboBuilder/getColumns.d.ts.map +1 -1
  133. package/dist/DboBuilder/getColumns.js +19 -26
  134. package/dist/DboBuilder/getColumns.js.map +1 -1
  135. package/dist/DboBuilder/getCondition.d.ts.map +1 -1
  136. package/dist/DboBuilder/getCondition.js +7 -9
  137. package/dist/DboBuilder/getCondition.js.map +1 -1
  138. package/dist/DboBuilder/getSubscribeRelatedTables.js +2 -2
  139. package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -1
  140. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.d.ts.map +1 -1
  141. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js +14 -15
  142. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js.map +1 -1
  143. package/dist/DboBuilder/insertNestedRecords.d.ts.map +1 -1
  144. package/dist/DboBuilder/insertNestedRecords.js +26 -40
  145. package/dist/DboBuilder/insertNestedRecords.js.map +1 -1
  146. package/dist/DboBuilder/parseUpdateRules.js +1 -1
  147. package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
  148. package/dist/DboBuilder/prepareShortestJoinPaths.d.ts.map +1 -1
  149. package/dist/DboBuilder/prepareShortestJoinPaths.js +12 -18
  150. package/dist/DboBuilder/prepareShortestJoinPaths.js.map +1 -1
  151. package/dist/DboBuilder/runSQL.d.ts +1 -1
  152. package/dist/DboBuilder/runSQL.d.ts.map +1 -1
  153. package/dist/DboBuilder/runSQL.js +14 -27
  154. package/dist/DboBuilder/runSQL.js.map +1 -1
  155. package/dist/DboBuilder/uploadFile.d.ts +1 -1
  156. package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
  157. package/dist/DboBuilder/uploadFile.js +4 -11
  158. package/dist/DboBuilder/uploadFile.js.map +1 -1
  159. package/dist/FileManager/FileManager.d.ts.map +1 -1
  160. package/dist/FileManager/FileManager.js +11 -13
  161. package/dist/FileManager/FileManager.js.map +1 -1
  162. package/dist/FileManager/initFileManager.d.ts.map +1 -1
  163. package/dist/FileManager/initFileManager.js +60 -62
  164. package/dist/FileManager/initFileManager.js.map +1 -1
  165. package/dist/FileManager/uploadStream.js +2 -2
  166. package/dist/FileManager/uploadStream.js.map +1 -1
  167. package/dist/Filtering.d.ts +1 -1
  168. package/dist/Filtering.d.ts.map +1 -1
  169. package/dist/Filtering.js +12 -35
  170. package/dist/Filtering.js.map +1 -1
  171. package/dist/JSONBValidation/validation.d.ts.map +1 -1
  172. package/dist/JSONBValidation/validation.js +20 -26
  173. package/dist/JSONBValidation/validation.js.map +1 -1
  174. package/dist/Logging.d.ts +1 -0
  175. package/dist/Logging.d.ts.map +1 -1
  176. package/dist/PostgresNotifListenManager.d.ts.map +1 -1
  177. package/dist/PostgresNotifListenManager.js +1 -5
  178. package/dist/PostgresNotifListenManager.js.map +1 -1
  179. package/dist/Prostgles.d.ts +1 -1
  180. package/dist/Prostgles.d.ts.map +1 -1
  181. package/dist/Prostgles.js +18 -33
  182. package/dist/Prostgles.js.map +1 -1
  183. package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
  184. package/dist/PubSubManager/PubSubManager.js +8 -13
  185. package/dist/PubSubManager/PubSubManager.js.map +1 -1
  186. package/dist/PubSubManager/addSub.d.ts.map +1 -1
  187. package/dist/PubSubManager/addSub.js +1 -1
  188. package/dist/PubSubManager/addSub.js.map +1 -1
  189. package/dist/PubSubManager/addSync.d.ts.map +1 -1
  190. package/dist/PubSubManager/addSync.js +4 -7
  191. package/dist/PubSubManager/addSync.js.map +1 -1
  192. package/dist/PubSubManager/getCreatePubSubManagerError.js +6 -6
  193. package/dist/PubSubManager/getCreatePubSubManagerError.js.map +1 -1
  194. package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
  195. package/dist/PubSubManager/initPubSubManager.js +2 -3
  196. package/dist/PubSubManager/initPubSubManager.js.map +1 -1
  197. package/dist/PubSubManager/pushSubData.d.ts.map +1 -1
  198. package/dist/PubSubManager/pushSubData.js +0 -2
  199. package/dist/PubSubManager/pushSubData.js.map +1 -1
  200. package/dist/PublishParser/PublishParser.d.ts.map +1 -1
  201. package/dist/PublishParser/PublishParser.js +8 -13
  202. package/dist/PublishParser/PublishParser.js.map +1 -1
  203. package/dist/PublishParser/getFileTableRules.js +1 -1
  204. package/dist/PublishParser/getFileTableRules.js.map +1 -1
  205. package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
  206. package/dist/PublishParser/getSchemaFromPublish.js +6 -13
  207. package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
  208. package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
  209. package/dist/PublishParser/getTableRulesWithoutFileTable.js +14 -19
  210. package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
  211. package/dist/RestApi.d.ts +1 -1
  212. package/dist/RestApi.d.ts.map +1 -1
  213. package/dist/RestApi.js +2 -2
  214. package/dist/RestApi.js.map +1 -1
  215. package/dist/SchemaWatch/SchemaWatch.d.ts.map +1 -1
  216. package/dist/SchemaWatch/SchemaWatch.js +2 -2
  217. package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
  218. package/dist/SyncReplication.d.ts.map +1 -1
  219. package/dist/SyncReplication.js +31 -41
  220. package/dist/SyncReplication.js.map +1 -1
  221. package/dist/TableConfig/TableConfig.d.ts.map +1 -1
  222. package/dist/TableConfig/TableConfig.js +7 -9
  223. package/dist/TableConfig/TableConfig.js.map +1 -1
  224. package/dist/TableConfig/getConstraintDefinitionQueries.d.ts.map +1 -1
  225. package/dist/TableConfig/getConstraintDefinitionQueries.js +1 -6
  226. package/dist/TableConfig/getConstraintDefinitionQueries.js.map +1 -1
  227. package/dist/TableConfig/getFutureTableSchema.d.ts.map +1 -1
  228. package/dist/TableConfig/getFutureTableSchema.js +16 -28
  229. package/dist/TableConfig/getFutureTableSchema.js.map +1 -1
  230. package/dist/TableConfig/getTableColumnQueries.d.ts.map +1 -1
  231. package/dist/TableConfig/getTableColumnQueries.js +5 -9
  232. package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
  233. package/dist/TableConfig/initTableConfig.d.ts.map +1 -1
  234. package/dist/TableConfig/initTableConfig.js +22 -25
  235. package/dist/TableConfig/initTableConfig.js.map +1 -1
  236. package/dist/initProstgles.js +1 -1
  237. package/dist/initProstgles.js.map +1 -1
  238. package/dist/onSocketConnected.d.ts.map +1 -1
  239. package/dist/onSocketConnected.js +2 -4
  240. package/dist/onSocketConnected.js.map +1 -1
  241. package/dist/runClientRequest.d.ts.map +1 -1
  242. package/dist/runClientRequest.js +14 -13
  243. package/dist/runClientRequest.js.map +1 -1
  244. package/lib/Auth/AuthHandler.ts +117 -137
  245. package/lib/Auth/AuthTypes.ts +97 -81
  246. package/lib/Auth/authProviders/setEmailProvider.ts +29 -0
  247. package/lib/Auth/authProviders/setOAuthProviders.ts +97 -0
  248. package/lib/Auth/endpoints/getConfirmEmailRequestHandler.ts +39 -0
  249. package/lib/Auth/endpoints/getRegisterRequestHandler.ts +83 -0
  250. package/lib/Auth/setAuthProviders.ts +8 -111
  251. package/lib/Auth/setupAuthRoutes.ts +105 -148
  252. package/lib/Auth/utils/checkDmarc.ts +19 -0
  253. package/lib/Auth/utils/getClientRequestIPsInfo.ts +25 -0
  254. package/lib/Auth/utils/getReturnUrl.ts +13 -0
  255. package/lib/DBEventsManager.ts +12 -26
  256. package/lib/DBSchemaBuilder.ts +1 -1
  257. package/lib/DboBuilder/DboBuilder.ts +23 -52
  258. package/lib/DboBuilder/DboBuilderTypes.ts +9 -23
  259. package/lib/DboBuilder/QueryBuilder/Functions.ts +86 -188
  260. package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +11 -36
  261. package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +102 -129
  262. package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +14 -27
  263. package/lib/DboBuilder/QueryStreamer.ts +26 -57
  264. package/lib/DboBuilder/TableHandler/DataValidator.ts +58 -90
  265. package/lib/DboBuilder/TableHandler/TableHandler.ts +19 -45
  266. package/lib/DboBuilder/TableHandler/delete.ts +9 -18
  267. package/lib/DboBuilder/TableHandler/insert.ts +18 -31
  268. package/lib/DboBuilder/TableHandler/insertTest.ts +1 -1
  269. package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +8 -19
  270. package/lib/DboBuilder/TableHandler/update.ts +17 -46
  271. package/lib/DboBuilder/TableHandler/updateFile.ts +18 -21
  272. package/lib/DboBuilder/TableHandler/upsert.ts +7 -24
  273. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +13 -15
  274. package/lib/DboBuilder/ViewHandler/count.ts +1 -1
  275. package/lib/DboBuilder/ViewHandler/find.ts +28 -35
  276. package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +8 -30
  277. package/lib/DboBuilder/ViewHandler/getInfo.ts +2 -2
  278. package/lib/DboBuilder/ViewHandler/getTableJoinQuery.ts +16 -32
  279. package/lib/DboBuilder/ViewHandler/parseFieldFilter.ts +9 -16
  280. package/lib/DboBuilder/ViewHandler/parseJoinPath.ts +26 -44
  281. package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +58 -82
  282. package/lib/DboBuilder/ViewHandler/prepareWhere.ts +14 -27
  283. package/lib/DboBuilder/dboBuilderUtils.ts +19 -46
  284. package/lib/DboBuilder/getColumns.ts +24 -46
  285. package/lib/DboBuilder/getCondition.ts +18 -30
  286. package/lib/DboBuilder/getSubscribeRelatedTables.ts +2 -2
  287. package/lib/DboBuilder/getTablesForSchemaPostgresSQL.ts +44 -62
  288. package/lib/DboBuilder/insertNestedRecords.ts +67 -135
  289. package/lib/DboBuilder/parseUpdateRules.ts +1 -1
  290. package/lib/DboBuilder/prepareShortestJoinPaths.ts +23 -58
  291. package/lib/DboBuilder/runSQL.ts +41 -76
  292. package/lib/DboBuilder/uploadFile.ts +26 -37
  293. package/lib/FileManager/FileManager.ts +27 -58
  294. package/lib/FileManager/initFileManager.ts +68 -76
  295. package/lib/FileManager/uploadStream.ts +2 -2
  296. package/lib/Filtering.ts +30 -87
  297. package/lib/JSONBValidation/validation.ts +36 -75
  298. package/lib/Logging.ts +1 -1
  299. package/lib/PostgresNotifListenManager.ts +11 -35
  300. package/lib/Prostgles.ts +42 -100
  301. package/lib/PubSubManager/PubSubManager.ts +30 -66
  302. package/lib/PubSubManager/addSub.ts +11 -18
  303. package/lib/PubSubManager/addSync.ts +5 -12
  304. package/lib/PubSubManager/getCreatePubSubManagerError.ts +9 -9
  305. package/lib/PubSubManager/initPubSubManager.ts +7 -13
  306. package/lib/PubSubManager/pushSubData.ts +1 -7
  307. package/lib/PublishParser/PublishParser.ts +8 -12
  308. package/lib/PublishParser/getFileTableRules.ts +1 -1
  309. package/lib/PublishParser/getSchemaFromPublish.ts +26 -42
  310. package/lib/PublishParser/getTableRulesWithoutFileTable.ts +22 -37
  311. package/lib/RestApi.ts +4 -12
  312. package/lib/SchemaWatch/SchemaWatch.ts +11 -24
  313. package/lib/SyncReplication.ts +96 -190
  314. package/lib/TableConfig/TableConfig.ts +16 -38
  315. package/lib/TableConfig/getConstraintDefinitionQueries.ts +2 -8
  316. package/lib/TableConfig/getFutureTableSchema.ts +20 -34
  317. package/lib/TableConfig/getTableColumnQueries.ts +13 -35
  318. package/lib/TableConfig/initTableConfig.ts +40 -64
  319. package/lib/initProstgles.ts +1 -1
  320. package/lib/onSocketConnected.ts +8 -12
  321. package/lib/runClientRequest.ts +31 -54
  322. package/package.json +2 -2
  323. package/dist/Auth/getSafeReturnURL.d.ts.map +0 -1
  324. package/dist/Auth/getSafeReturnURL.js.map +0 -1
  325. package/dist/Auth/setEmailProvider.d.ts.map +0 -1
  326. package/dist/Auth/setEmailProvider.js +0 -133
  327. package/dist/Auth/setEmailProvider.js.map +0 -1
  328. package/dist/DboBuilder/runTransaction.d.ts +0 -9
  329. package/dist/DboBuilder/runTransaction.d.ts.map +0 -1
  330. package/dist/DboBuilder/runTransaction.js +0 -49
  331. package/dist/DboBuilder/runTransaction.js.map +0 -1
  332. package/lib/Auth/setEmailProvider.ts +0 -132
  333. package/lib/DboBuilder/QueryBuilder/prepareHaving.ts +0 -27
  334. package/lib/DboBuilder/runTransaction.ts +0 -61
  335. package/lib/SchemaWatch/createSchemaWatchEventTrigger.ts +0 -3
  336. /package/dist/Auth/{getSafeReturnURL.d.ts → utils/getSafeReturnURL.d.ts} +0 -0
  337. /package/dist/Auth/{getSafeReturnURL.js → utils/getSafeReturnURL.js} +0 -0
  338. /package/lib/Auth/{getSafeReturnURL.ts → utils/getSafeReturnURL.ts} +0 -0
@@ -1,27 +1,27 @@
1
1
  import { Express, NextFunction, Request, Response } from "express";
2
+ import Mail from "nodemailer/lib/mailer";
3
+ import type { AuthenticateOptions } from "passport";
4
+ import type {
5
+ Profile as FacebookProfile,
6
+ StrategyOptions as FacebookStrategy,
7
+ } from "passport-facebook";
8
+ import type { Profile as GitHubProfile, StrategyOptions as GitHubStrategy } from "passport-github2";
9
+ import type {
10
+ Profile as GoogleProfile,
11
+ StrategyOptions as GoogleStrategy,
12
+ } from "passport-google-oauth20";
13
+ import type { MicrosoftStrategyOptions } from "passport-microsoft";
2
14
  import {
3
15
  AnyObject,
4
- EmailLoginResponse,
5
- EmailRegisterResponse,
6
16
  FieldFilter,
7
17
  IdentityProvider,
18
+ AuthResponse,
8
19
  UserLike,
20
+ AuthRequest,
9
21
  } from "prostgles-types";
10
- import { DB } from "../Prostgles";
11
22
  import { DBOFullyTyped } from "../DBSchemaBuilder";
12
23
  import { PRGLIOSocket } from "../DboBuilder/DboBuilderTypes";
13
- import type { AuthenticateOptions } from "passport";
14
- import type {
15
- StrategyOptions as GoogleStrategy,
16
- Profile as GoogleProfile,
17
- } from "passport-google-oauth20";
18
- import type { StrategyOptions as GitHubStrategy, Profile as GitHubProfile } from "passport-github2";
19
- import type { MicrosoftStrategyOptions } from "passport-microsoft";
20
- import type {
21
- StrategyOptions as FacebookStrategy,
22
- Profile as FacebookProfile,
23
- } from "passport-facebook";
24
- import Mail from "nodemailer/lib/mailer";
24
+ import { DB } from "../Prostgles";
25
25
 
26
26
  type Awaitable<T> = T | Promise<T>;
27
27
 
@@ -96,54 +96,55 @@ export type Email = {
96
96
 
97
97
  type EmailWithoutTo = Omit<Email, "to">;
98
98
 
99
- type EmailProvider =
99
+ type MagicLinkAuthResponse =
100
+ | { response: AuthResponse.MagicLinkAuthFailure; email?: undefined }
101
+ | { response: AuthResponse.MagicLinkAuthSuccess; email: EmailWithoutTo };
102
+
103
+ type PasswordRegisterResponse =
104
+ | { response: AuthResponse.PasswordRegisterFailure; email?: undefined }
105
+ | { response: AuthResponse.PasswordRegisterSuccess; email: EmailWithoutTo };
106
+
107
+ export type EmailProvider =
100
108
  | {
101
109
  signupType: "withMagicLink";
102
- onRegistered: (data: { username: string }) => Awaitable<EmailRegisterResponse>;
103
- emailMagicLink: {
104
- onSend: (data: {
105
- email: string;
106
- magicLinkPath: string;
107
- clientInfo: LoginClientInfo;
108
- req: ExpressReq;
109
- }) => EmailWithoutTo | Promise<EmailWithoutTo>;
110
- smtp: SMTPConfig;
111
- };
110
+ onRegister: (data: {
111
+ email: string;
112
+ magicLinkUrlPath: string;
113
+ clientInfo: LoginClientInfo;
114
+ req: ExpressReq;
115
+ }) => Awaitable<MagicLinkAuthResponse>;
116
+ smtp: SMTPConfig;
112
117
  }
113
118
  | {
119
+ /**
120
+ * Users have to provide an email and a password.
121
+ * Account should be activated after email confirmation
122
+ */
114
123
  signupType: "withPassword";
115
- onRegistered: (
116
- data: { username: string; password: string },
117
- clientInfo: LoginClientInfo
118
- ) => Awaitable<EmailRegisterResponse>;
119
124
  /**
120
125
  * Defaults to 8
121
126
  */
122
127
  minPasswordLength?: number;
123
128
  /**
124
- * If provided, the user will be required to confirm their email address
129
+ * Called when the user has registered
125
130
  */
126
- emailConfirmation?: {
127
- /**
128
- * Called when the user has registered
129
- */
130
- onSend: (data: {
131
- email: string;
132
- password: string;
133
- confirmationUrlPath: string;
134
- clientInfo: LoginClientInfo;
135
- req: ExpressReq;
136
- }) => EmailWithoutTo | Promise<EmailWithoutTo>;
137
- smtp: SMTPConfig;
138
- /**
139
- * Called after the user has clicked the URL to confirm their email address
140
- */
141
- onConfirmed: (data: {
142
- confirmationCode: string;
143
- clientInfo: LoginClientInfo;
144
- req: ExpressReq;
145
- }) => void | Promise<void>;
146
- };
131
+ onRegister: (data: {
132
+ email: string;
133
+ password: string;
134
+ confirmationUrlPath: string;
135
+ clientInfo: LoginClientInfo;
136
+ req: ExpressReq;
137
+ }) => Awaitable<PasswordRegisterResponse>;
138
+ smtp: SMTPConfig;
139
+
140
+ /**
141
+ * Called after the user has clicked the URL to confirm their email address
142
+ */
143
+ onEmailConfirmation: (data: {
144
+ confirmationCode: string;
145
+ clientInfo: LoginClientInfo;
146
+ req: ExpressReq;
147
+ }) => void | Promise<void>;
147
148
  };
148
149
 
149
150
  export type AuthProviderUserData =
@@ -242,7 +243,7 @@ export type AuthResult<SU = SessionUser> =
242
243
  | {
243
244
  user?: undefined;
244
245
  clientUser?: undefined;
245
- sid?: string;
246
+ sid?: string | undefined;
246
247
  }
247
248
  | undefined;
248
249
 
@@ -260,9 +261,14 @@ export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
260
261
  sidKeyName?: string;
261
262
 
262
263
  /**
263
- * Response time rounding in milliseconds to prevent timing attacks on login. Login response time should always be a multiple of this value. Defaults to 500 milliseconds
264
+ * undefined sid is allowed to enable public users
264
265
  */
265
- responseThrottle?: number;
266
+ getUser: (
267
+ sid: string | undefined,
268
+ dbo: DBOFullyTyped<S>,
269
+ db: DB,
270
+ client: AuthClientRequest & LoginClientInfo
271
+ ) => Awaitable<AuthResult<SUser>>;
266
272
 
267
273
  /**
268
274
  * Will setup auth routes
@@ -272,16 +278,6 @@ export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
272
278
  */
273
279
  expressConfig?: ExpressConfig<S, SUser>;
274
280
 
275
- /**
276
- * undefined sid is allowed to enable public users
277
- */
278
- getUser: (
279
- sid: string | undefined,
280
- dbo: DBOFullyTyped<S>,
281
- db: DB,
282
- client: AuthClientRequest & LoginClientInfo
283
- ) => Awaitable<AuthResult<SUser>>;
284
-
285
281
  login?: (
286
282
  params: LoginParams,
287
283
  dbo: DBOFullyTyped<S>,
@@ -290,18 +286,35 @@ export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
290
286
  ) => Awaitable<LoginResponse>;
291
287
  logout?: (sid: string | undefined, dbo: DBOFullyTyped<S>, db: DB) => Awaitable<any>;
292
288
 
289
+ /**
290
+ * Response time rounding in milliseconds to prevent timing attacks on login. Login response time should always be a multiple of this value. Defaults to 500 milliseconds
291
+ */
292
+ responseThrottle?: number;
293
+
293
294
  /**
294
295
  * If provided then session info will be saved on socket.__prglCache and reused from there
295
296
  */
296
297
  cacheSession?: {
297
- getSession: (sid: string | undefined, dbo: DBOFullyTyped<S>, db: DB) => Awaitable<BasicSession>;
298
+ getSession: (
299
+ sid: string | undefined,
300
+ dbo: DBOFullyTyped<S>,
301
+ db: DB
302
+ ) => Awaitable<BasicSession | undefined>;
298
303
  };
299
304
  };
300
305
 
301
- export type LoginResponse = BasicSession | Exclude<EmailLoginResponse, { success: true }>;
306
+ export type LoginResponse =
307
+ | {
308
+ session: BasicSession;
309
+ response?: AuthResponse.PasswordLoginSuccess | AuthResponse.MagicLinkAuthSuccess;
310
+ }
311
+ | {
312
+ session?: undefined;
313
+ response: AuthResponse.PasswordLoginFailure | AuthResponse.MagicLinkAuthFailure;
314
+ };
302
315
 
303
316
  export type LoginParams =
304
- | { type: "username"; username: string; password: string; [key: string]: any }
317
+ | ({ type: "username" } & AuthRequest.LoginData)
305
318
  | ({ type: "provider" } & AuthProviderUserData);
306
319
 
307
320
  type ExpressConfig<S, SUser extends SessionUser> = {
@@ -336,22 +349,25 @@ type ExpressConfig<S, SUser extends SessionUser> = {
336
349
  * Will be called after a GET request is authorised
337
350
  * This means that
338
351
  */
339
- onGetRequestOK?: (req: ExpressReq, res: ExpressRes, params: AuthRequestParams<S, SUser>) => any;
352
+ onGetRequestOK?: (
353
+ req: ExpressReq,
354
+ res: ExpressRes,
355
+ params: AuthRequestParams<S, SUser>
356
+ ) => Awaitable<void>;
340
357
 
341
358
  /**
342
- * If defined, will check the magic link id and log in the user and redirect to the returnUrl if set
359
+ * If defined, will enable GET /magic-link/:id route.
360
+ * Requests with valid magic link ids will be logged in and redirected to the returnUrl if set
343
361
  */
344
- magicLinks?: {
345
- /**
346
- * Used in creating a session/logging in using a magic link
347
- */
348
- check: (
349
- magicId: string,
350
- dbo: DBOFullyTyped<S>,
351
- db: DB,
352
- client: LoginClientInfo
353
- ) => Awaitable<BasicSession | undefined>;
354
- };
362
+ onMagicLink?: (
363
+ magicId: string,
364
+ dbo: DBOFullyTyped<S>,
365
+ db: DB,
366
+ client: LoginClientInfo
367
+ ) => Awaitable<
368
+ | { session: BasicSession; response?: AuthResponse.MagicLinkAuthSuccess }
369
+ | { session?: undefined; response: AuthResponse.MagicLinkAuthFailure }
370
+ >;
355
371
 
356
372
  registrations?: AuthRegistrationConfig<S>;
357
373
  };
@@ -0,0 +1,29 @@
1
+ import e from "express";
2
+ import { AUTH_ROUTES_AND_PARAMS, AuthHandler } from "../AuthHandler";
3
+ import { getConfirmEmailRequestHandler } from "../endpoints/getConfirmEmailRequestHandler";
4
+ import { getRegisterRequestHandler } from "../endpoints/getRegisterRequestHandler";
5
+ import { getOrSetTransporter } from "../sendEmail";
6
+ import { checkDmarc } from "../utils/checkDmarc";
7
+
8
+ export async function setEmailProvider(this: AuthHandler, app: e.Express) {
9
+ const { email, websiteUrl } = this.opts.expressConfig?.registrations ?? {};
10
+ if (!email) return;
11
+ if (!websiteUrl) {
12
+ throw new Error("websiteUrl is required for email/magic-link registrations");
13
+ }
14
+ await checkDmarc(websiteUrl);
15
+
16
+ /**
17
+ * Setup nodemailer transporters
18
+ */
19
+ getOrSetTransporter(email.smtp);
20
+
21
+ app.post(
22
+ AUTH_ROUTES_AND_PARAMS.emailRegistration,
23
+ getRegisterRequestHandler({ email, websiteUrl })
24
+ );
25
+
26
+ if (email.signupType === "withPassword") {
27
+ app.get(AUTH_ROUTES_AND_PARAMS.confirmEmailExpressRoute, getConfirmEmailRequestHandler(email));
28
+ }
29
+ }
@@ -0,0 +1,97 @@
1
+ import * as passport from "passport";
2
+ import { Strategy as FacebookStrategy } from "passport-facebook";
3
+ import { Strategy as GitHubStrategy } from "passport-github2";
4
+ import { Strategy as GoogleStrategy } from "passport-google-oauth20";
5
+ import { Strategy as MicrosoftStrategy } from "passport-microsoft";
6
+ import { getObjectEntries, isEmpty } from "prostgles-types";
7
+ import { getErrorAsObject } from "../../DboBuilder/dboBuilderUtils";
8
+ import { AUTH_ROUTES_AND_PARAMS, AuthHandler } from "../AuthHandler";
9
+ import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
10
+ import { AuthRegistrationConfig } from "../AuthTypes";
11
+ import { upsertNamedExpressMiddleware } from "../setAuthProviders";
12
+ import e from "express";
13
+
14
+ export function setOAuthProviders(
15
+ this: AuthHandler,
16
+ app: e.Express,
17
+ registrations: AuthRegistrationConfig<void>
18
+ ) {
19
+ const { onProviderLoginFail, onProviderLoginStart, websiteUrl, OAuthProviders } = registrations;
20
+ if (!OAuthProviders || isEmpty(OAuthProviders)) {
21
+ return;
22
+ }
23
+
24
+ upsertNamedExpressMiddleware(app, passport.initialize(), "prostglesPassportMiddleware");
25
+
26
+ getObjectEntries(OAuthProviders).forEach(([providerName, providerConfig]) => {
27
+ if (!providerConfig?.clientID) {
28
+ return;
29
+ }
30
+
31
+ const { authOpts, ...config } = providerConfig;
32
+
33
+ const strategy =
34
+ providerName === "google" ? GoogleStrategy
35
+ : providerName === "github" ? GitHubStrategy
36
+ : providerName === "facebook" ? FacebookStrategy
37
+ : MicrosoftStrategy;
38
+ const callbackPath = `${AUTH_ROUTES_AND_PARAMS.loginWithProvider}/${providerName}/callback`;
39
+ passport.use(
40
+ new (strategy as typeof GoogleStrategy)(
41
+ {
42
+ ...config,
43
+ callbackURL: `${websiteUrl}${callbackPath}`,
44
+ },
45
+ async (accessToken, refreshToken, profile, done) => {
46
+ // This callback is where you would normally store or retrieve user info from the database
47
+ return done(null, profile, { accessToken, refreshToken, profile });
48
+ }
49
+ )
50
+ );
51
+
52
+ app.get(
53
+ `${AUTH_ROUTES_AND_PARAMS.loginWithProvider}/${providerName}`,
54
+ passport.authenticate(providerName, authOpts ?? {})
55
+ );
56
+
57
+ app.get(callbackPath, async (req, res) => {
58
+ try {
59
+ const clientInfo = getClientRequestIPsInfo({ httpReq: req });
60
+ const db = this.db;
61
+ const dbo = this.dbo as any;
62
+ const args = { provider: providerName, req, res, clientInfo, db, dbo };
63
+ const startCheck = await onProviderLoginStart?.(args);
64
+ if (startCheck && "error" in startCheck) {
65
+ res.status(500).json({ error: startCheck.error });
66
+ return;
67
+ }
68
+ passport.authenticate(
69
+ providerName,
70
+ {
71
+ session: false,
72
+ failureRedirect: "/login",
73
+ failWithError: true,
74
+ },
75
+ async (error: any, _profile: any, authInfo: any) => {
76
+ if (error) {
77
+ await onProviderLoginFail?.({ ...args, error });
78
+ res.status(500).json({
79
+ error: "Failed to login with provider",
80
+ });
81
+ } else {
82
+ this.loginThrottledAndSetCookie(req, res, {
83
+ type: "provider",
84
+ provider: providerName,
85
+ ...authInfo,
86
+ }).catch((e: any) => {
87
+ res.status(500).json(getErrorAsObject(e));
88
+ });
89
+ }
90
+ }
91
+ )(req, res);
92
+ } catch (_e) {
93
+ res.status(500).json({ error: "Something went wrong" });
94
+ }
95
+ });
96
+ });
97
+ }
@@ -0,0 +1,39 @@
1
+ import type { Request, Response } from "express";
2
+ import { AuthResponse } from "prostgles-types";
3
+ import { HTTP_FAIL_CODES } from "../AuthHandler";
4
+ import { AuthRegistrationConfig } from "../AuthTypes";
5
+ import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
6
+
7
+ export const getConfirmEmailRequestHandler = (
8
+ emailAuthConfig: Extract<
9
+ Required<AuthRegistrationConfig<void>>["email"],
10
+ { signupType: "withPassword" }
11
+ >
12
+ ) => {
13
+ return async (
14
+ req: Request,
15
+ res: Response<
16
+ | AuthResponse.PasswordRegisterSuccess
17
+ | AuthResponse.PasswordRegisterFailure
18
+ | AuthResponse.AuthSuccess
19
+ >
20
+ ) => {
21
+ const { id } = req.params;
22
+ try {
23
+ if (!id || typeof id !== "string") {
24
+ return res.send({ success: false, code: "something-went-wrong", message: "Invalid code" });
25
+ }
26
+ const { httpReq, ...clientInfo } = getClientRequestIPsInfo({ httpReq: req });
27
+ await emailAuthConfig.onEmailConfirmation({
28
+ confirmationCode: id,
29
+ clientInfo,
30
+ req: httpReq,
31
+ });
32
+ res.json({ success: true, message: "Email confirmed" });
33
+ } catch (_e) {
34
+ res
35
+ .status(HTTP_FAIL_CODES.BAD_REQUEST)
36
+ .json({ success: false, code: "server-error", message: "Failed to confirm email" });
37
+ }
38
+ };
39
+ };
@@ -0,0 +1,83 @@
1
+ import { RequestHandler, Response, Request } from "express";
2
+ import { AuthResponse } from "prostgles-types";
3
+ import { AUTH_ROUTES_AND_PARAMS, HTTP_FAIL_CODES } from "../AuthHandler";
4
+ import type { AuthRegistrationConfig } from "../AuthTypes";
5
+ import { sendEmail } from "../sendEmail";
6
+ import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
7
+
8
+ type ReturnType =
9
+ | AuthResponse.MagicLinkAuthFailure
10
+ | AuthResponse.MagicLinkAuthSuccess
11
+ | AuthResponse.PasswordRegisterFailure
12
+ | AuthResponse.PasswordRegisterSuccess;
13
+
14
+ export const getRegisterRequestHandler = ({
15
+ email: emailAuthConfig,
16
+ websiteUrl,
17
+ }: Required<Pick<AuthRegistrationConfig<void>, "email" | "websiteUrl">>) => {
18
+ const registerRequestHandler = async (req: Request, res: Response<ReturnType>) => {
19
+ const { username, password } = req.body;
20
+ const sendResponse = (response: ReturnType) => {
21
+ if (response.success) {
22
+ res.json(response);
23
+ } else {
24
+ res.status(HTTP_FAIL_CODES.BAD_REQUEST).json(response);
25
+ }
26
+ };
27
+ if (!username || typeof username !== "string") {
28
+ return sendResponse({ success: false, code: "username-missing" });
29
+ }
30
+ if (emailAuthConfig.signupType === "withPassword") {
31
+ const { minPasswordLength = 8 } = emailAuthConfig;
32
+ if (typeof password !== "string") {
33
+ return sendResponse({ success: false, code: "password-missing" });
34
+ } else if (password.length < minPasswordLength) {
35
+ return sendResponse({
36
+ success: false,
37
+ code: "weak-password",
38
+ message: `Password must be at least ${minPasswordLength} characters long`,
39
+ });
40
+ }
41
+ }
42
+ try {
43
+ const { httpReq, ...clientInfo } = getClientRequestIPsInfo({ httpReq: req });
44
+ const { smtp } = emailAuthConfig;
45
+ const registrationResult =
46
+ emailAuthConfig.signupType === "withPassword" ?
47
+ await emailAuthConfig.onRegister({
48
+ email: username,
49
+ password,
50
+ confirmationUrlPath: `${websiteUrl}${AUTH_ROUTES_AND_PARAMS.confirmEmail}`,
51
+ clientInfo,
52
+ req: httpReq,
53
+ })
54
+ : await emailAuthConfig.onRegister({
55
+ email: username,
56
+ magicLinkUrlPath: `${websiteUrl}${AUTH_ROUTES_AND_PARAMS.magicLinksRoute}`,
57
+ clientInfo,
58
+ req: httpReq,
59
+ });
60
+ if (!registrationResult.email) {
61
+ return sendResponse(registrationResult.response);
62
+ }
63
+
64
+ const emailMessage = { ...registrationResult.email, to: username };
65
+ await sendEmail(smtp, emailMessage);
66
+ return sendResponse({
67
+ ...registrationResult.response,
68
+ message:
69
+ emailAuthConfig.signupType === "withPassword" ?
70
+ `We've sent a confirmation email to ${emailMessage.to}. Please check your inbox (and your spam folder) for a message from us.`
71
+ : "Email sent",
72
+ });
73
+ } catch {
74
+ return sendResponse({
75
+ success: false,
76
+ code: "server-error",
77
+ message: "Failed to send email",
78
+ });
79
+ }
80
+ };
81
+
82
+ return registerRequestHandler;
83
+ };
@@ -1,25 +1,16 @@
1
1
  import type e from "express";
2
2
  import { RequestHandler } from "express";
3
- import { Strategy as FacebookStrategy } from "passport-facebook";
4
- import { Strategy as GitHubStrategy } from "passport-github2";
5
- import { Strategy as GoogleStrategy } from "passport-google-oauth20";
6
- import { Strategy as MicrosoftStrategy } from "passport-microsoft";
7
3
  import { AuthSocketSchema, getObjectEntries, isEmpty } from "prostgles-types";
8
- import { getErrorAsObject } from "../DboBuilder/dboBuilderUtils";
9
4
  import { removeExpressRouteByName } from "../FileManager/FileManager";
10
- import {
11
- AUTH_ROUTES_AND_PARAMS,
12
- AuthHandler,
13
- getLoginClientInfo,
14
- } from "./AuthHandler";
5
+ import { AUTH_ROUTES_AND_PARAMS, AuthHandler } from "./AuthHandler";
15
6
  import { Auth } from "./AuthTypes";
16
- import { setEmailProvider } from "./setEmailProvider";
17
- import * as passport from "passport";
7
+ import { setEmailProvider } from "./authProviders/setEmailProvider";
8
+ import { setOAuthProviders } from "./authProviders/setOAuthProviders";
18
9
 
19
10
  export const upsertNamedExpressMiddleware = (
20
11
  app: e.Express,
21
12
  handler: RequestHandler,
22
- name: string,
13
+ name: string
23
14
  ) => {
24
15
  const funcName = name;
25
16
  Object.defineProperty(handler, "name", { value: funcName });
@@ -29,110 +20,16 @@ export const upsertNamedExpressMiddleware = (
29
20
 
30
21
  export async function setAuthProviders(
31
22
  this: AuthHandler,
32
- { registrations, app }: Required<Auth>["expressConfig"],
23
+ { registrations, app }: Required<Auth>["expressConfig"]
33
24
  ) {
34
25
  if (!registrations) return;
35
- const {
36
- onProviderLoginFail,
37
- onProviderLoginStart,
38
- websiteUrl,
39
- OAuthProviders,
40
- } = registrations;
41
26
 
42
27
  await setEmailProvider.bind(this)(app);
43
-
44
- if (!OAuthProviders || isEmpty(OAuthProviders)) {
45
- return;
46
- }
47
-
48
- upsertNamedExpressMiddleware(
49
- app,
50
- passport.initialize(),
51
- "prostglesPassportMiddleware",
52
- );
53
-
54
- getObjectEntries(OAuthProviders).forEach(([providerName, providerConfig]) => {
55
- if (!providerConfig?.clientID) {
56
- return;
57
- }
58
-
59
- const { authOpts, ...config } = providerConfig;
60
-
61
- const strategy =
62
- providerName === "google"
63
- ? GoogleStrategy
64
- : providerName === "github"
65
- ? GitHubStrategy
66
- : providerName === "facebook"
67
- ? FacebookStrategy
68
- : providerName === "microsoft"
69
- ? MicrosoftStrategy
70
- : undefined;
71
- const callbackPath = `${AUTH_ROUTES_AND_PARAMS.loginWithProvider}/${providerName}/callback`;
72
- passport.use(
73
- new (strategy as typeof GoogleStrategy)(
74
- {
75
- ...config,
76
- callbackURL: `${websiteUrl}${callbackPath}`,
77
- },
78
- async (accessToken, refreshToken, profile, done) => {
79
- // This callback is where you would normally store or retrieve user info from the database
80
- return done(null, profile, { accessToken, refreshToken, profile });
81
- },
82
- ),
83
- );
84
-
85
- app.get(
86
- `${AUTH_ROUTES_AND_PARAMS.loginWithProvider}/${providerName}`,
87
- passport.authenticate(providerName, authOpts ?? {}),
88
- );
89
-
90
- app.get(callbackPath, async (req, res) => {
91
- try {
92
- const clientInfo = getLoginClientInfo({ httpReq: req });
93
- const db = this.db;
94
- const dbo = this.dbo as any;
95
- const args = { provider: providerName, req, res, clientInfo, db, dbo };
96
- const startCheck = await onProviderLoginStart?.(args);
97
- if (startCheck && "error" in startCheck) {
98
- res.status(500).json({ error: startCheck.error });
99
- return;
100
- }
101
- passport.authenticate(
102
- providerName,
103
- {
104
- session: false,
105
- failureRedirect: "/login",
106
- failWithError: true,
107
- },
108
- async (error: any, _profile: any, authInfo: any) => {
109
- if (error) {
110
- await onProviderLoginFail?.({ ...args, error });
111
- res.status(500).json({
112
- error: "Failed to login with provider",
113
- });
114
- } else {
115
- this.loginThrottledAndSetCookie(req, res, {
116
- type: "provider",
117
- provider: providerName,
118
- ...authInfo,
119
- }).catch((e: any) => {
120
- res.status(500).json(getErrorAsObject(e));
121
- });
122
- }
123
- },
124
- )(req, res);
125
- } catch (_e) {
126
- res.status(500).json({ error: "Something went wrong" });
127
- }
128
- });
129
- });
28
+ await setOAuthProviders.bind(this)(app, registrations);
130
29
  }
131
30
 
132
- export function getProviders(
133
- this: AuthHandler,
134
- ): AuthSocketSchema["providers"] | undefined {
135
- const { registrations } = this.opts?.expressConfig ?? {};
31
+ export function getProviders(this: AuthHandler): AuthSocketSchema["providers"] | undefined {
32
+ const { registrations } = this.opts.expressConfig ?? {};
136
33
  if (!registrations) return undefined;
137
34
  const { OAuthProviders } = registrations;
138
35
  if (!OAuthProviders || isEmpty(OAuthProviders)) return undefined;