prostgles-server 4.2.187 → 4.2.189
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.
- package/.eslintignore +2 -1
- package/.eslintrc.json +2 -0
- package/dist/Auth/AuthHandler.d.ts +20 -11
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +98 -120
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +69 -71
- package/dist/Auth/AuthTypes.d.ts.map +1 -1
- package/dist/Auth/{setEmailProvider.d.ts → authProviders/setEmailProvider.d.ts} +1 -1
- package/dist/Auth/authProviders/setEmailProvider.d.ts.map +1 -0
- package/dist/Auth/authProviders/setEmailProvider.js +27 -0
- package/dist/Auth/authProviders/setEmailProvider.js.map +1 -0
- package/dist/Auth/authProviders/setOAuthProviders.d.ts +5 -0
- package/dist/Auth/authProviders/setOAuthProviders.d.ts.map +1 -0
- package/dist/Auth/authProviders/setOAuthProviders.js +78 -0
- package/dist/Auth/authProviders/setOAuthProviders.js.map +1 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts +7 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts.map +1 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js +29 -0
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js.map +1 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts +7 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts.map +1 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.js +77 -0
- package/dist/Auth/endpoints/getRegisterRequestHandler.js.map +1 -0
- package/dist/Auth/setAuthProviders.d.ts.map +1 -1
- package/dist/Auth/setAuthProviders.js +4 -74
- package/dist/Auth/setAuthProviders.js.map +1 -1
- package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
- package/dist/Auth/setupAuthRoutes.js +23 -33
- package/dist/Auth/setupAuthRoutes.js.map +1 -1
- package/dist/Auth/utils/checkDmarc.d.ts +2 -0
- package/dist/Auth/utils/checkDmarc.d.ts.map +1 -0
- package/dist/Auth/utils/checkDmarc.js +22 -0
- package/dist/Auth/utils/checkDmarc.js.map +1 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.d.ts +3 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.d.ts.map +1 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.js +29 -0
- package/dist/Auth/utils/getClientRequestIPsInfo.js.map +1 -0
- package/dist/Auth/utils/getReturnUrl.d.ts +3 -0
- package/dist/Auth/utils/getReturnUrl.d.ts.map +1 -0
- package/dist/Auth/utils/getReturnUrl.js +15 -0
- package/dist/Auth/utils/getReturnUrl.js.map +1 -0
- package/dist/Auth/utils/getSafeReturnURL.d.ts.map +1 -0
- package/dist/Auth/utils/getSafeReturnURL.js.map +1 -0
- package/dist/DBEventsManager.d.ts.map +1 -1
- package/dist/DBEventsManager.js +4 -5
- package/dist/DBEventsManager.js.map +1 -1
- package/dist/DBSchemaBuilder.js +1 -1
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts +0 -1
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +3 -12
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.d.ts +4 -4
- package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions.js +38 -76
- package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +4 -12
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js +23 -33
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js +6 -6
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +13 -19
- package/dist/DboBuilder/QueryStreamer.js.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.js +7 -16
- package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.js +7 -5
- package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
- package/dist/DboBuilder/TableHandler/delete.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/delete.js +5 -8
- package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.js +10 -15
- package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insertTest.js +1 -1
- package/dist/DboBuilder/TableHandler/insertTest.js.map +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js +1 -1
- package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js.map +1 -1
- package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/update.js +5 -9
- package/dist/DboBuilder/TableHandler/update.js.map +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/updateFile.js +7 -9
- package/dist/DboBuilder/TableHandler/updateFile.js.map +1 -1
- package/dist/DboBuilder/TableHandler/upsert.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/upsert.js +1 -1
- package/dist/DboBuilder/TableHandler/upsert.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +11 -13
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/count.js +1 -1
- package/dist/DboBuilder/ViewHandler/count.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.js +20 -27
- package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js +4 -10
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getInfo.js +2 -2
- package/dist/DboBuilder/ViewHandler/getInfo.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js +6 -22
- package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseFieldFilter.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseFieldFilter.js +6 -10
- package/dist/DboBuilder/ViewHandler/parseFieldFilter.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseJoinPath.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseJoinPath.js +8 -11
- package/dist/DboBuilder/ViewHandler/parseJoinPath.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareSortItems.js +7 -12
- package/dist/DboBuilder/ViewHandler/prepareSortItems.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareWhere.js +6 -10
- package/dist/DboBuilder/ViewHandler/prepareWhere.js.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.js +8 -23
- package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
- package/dist/DboBuilder/getColumns.d.ts.map +1 -1
- package/dist/DboBuilder/getColumns.js +19 -26
- package/dist/DboBuilder/getColumns.js.map +1 -1
- package/dist/DboBuilder/getCondition.d.ts.map +1 -1
- package/dist/DboBuilder/getCondition.js +7 -9
- package/dist/DboBuilder/getCondition.js.map +1 -1
- package/dist/DboBuilder/getSubscribeRelatedTables.js +2 -2
- package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -1
- package/dist/DboBuilder/getTablesForSchemaPostgresSQL.d.ts.map +1 -1
- package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js +14 -15
- package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js.map +1 -1
- package/dist/DboBuilder/insertNestedRecords.d.ts.map +1 -1
- package/dist/DboBuilder/insertNestedRecords.js +26 -40
- package/dist/DboBuilder/insertNestedRecords.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +1 -1
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/DboBuilder/prepareShortestJoinPaths.d.ts.map +1 -1
- package/dist/DboBuilder/prepareShortestJoinPaths.js +12 -18
- package/dist/DboBuilder/prepareShortestJoinPaths.js.map +1 -1
- package/dist/DboBuilder/runSQL.d.ts +1 -1
- package/dist/DboBuilder/runSQL.d.ts.map +1 -1
- package/dist/DboBuilder/runSQL.js +14 -27
- package/dist/DboBuilder/runSQL.js.map +1 -1
- package/dist/DboBuilder/uploadFile.d.ts +1 -1
- package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
- package/dist/DboBuilder/uploadFile.js +4 -11
- package/dist/DboBuilder/uploadFile.js.map +1 -1
- package/dist/FileManager/FileManager.d.ts.map +1 -1
- package/dist/FileManager/FileManager.js +11 -13
- package/dist/FileManager/FileManager.js.map +1 -1
- package/dist/FileManager/initFileManager.d.ts.map +1 -1
- package/dist/FileManager/initFileManager.js +60 -62
- package/dist/FileManager/initFileManager.js.map +1 -1
- package/dist/FileManager/uploadStream.js +2 -2
- package/dist/FileManager/uploadStream.js.map +1 -1
- package/dist/Filtering.d.ts +1 -1
- package/dist/Filtering.d.ts.map +1 -1
- package/dist/Filtering.js +12 -35
- package/dist/Filtering.js.map +1 -1
- package/dist/JSONBValidation/validation.d.ts.map +1 -1
- package/dist/JSONBValidation/validation.js +20 -26
- package/dist/JSONBValidation/validation.js.map +1 -1
- package/dist/Logging.d.ts +1 -0
- package/dist/Logging.d.ts.map +1 -1
- package/dist/PostgresNotifListenManager.d.ts.map +1 -1
- package/dist/PostgresNotifListenManager.js +1 -5
- package/dist/PostgresNotifListenManager.js.map +1 -1
- package/dist/Prostgles.d.ts +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +18 -33
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +8 -13
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.d.ts.map +1 -1
- package/dist/PubSubManager/addSub.js +1 -1
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/addSync.d.ts.map +1 -1
- package/dist/PubSubManager/addSync.js +4 -7
- package/dist/PubSubManager/addSync.js.map +1 -1
- package/dist/PubSubManager/getCreatePubSubManagerError.js +6 -6
- package/dist/PubSubManager/getCreatePubSubManagerError.js.map +1 -1
- package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/initPubSubManager.js +2 -3
- package/dist/PubSubManager/initPubSubManager.js.map +1 -1
- package/dist/PubSubManager/pushSubData.d.ts.map +1 -1
- package/dist/PubSubManager/pushSubData.js +0 -2
- package/dist/PubSubManager/pushSubData.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +8 -13
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getFileTableRules.js +1 -1
- package/dist/PublishParser/getFileTableRules.js.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +6 -13
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js +14 -19
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
- package/dist/RestApi.d.ts +1 -1
- package/dist/RestApi.d.ts.map +1 -1
- package/dist/RestApi.js +2 -2
- package/dist/RestApi.js.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.d.ts.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.js +2 -2
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
- package/dist/SyncReplication.d.ts.map +1 -1
- package/dist/SyncReplication.js +31 -41
- package/dist/SyncReplication.js.map +1 -1
- package/dist/TableConfig/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig/TableConfig.js +7 -9
- package/dist/TableConfig/TableConfig.js.map +1 -1
- package/dist/TableConfig/getConstraintDefinitionQueries.d.ts.map +1 -1
- package/dist/TableConfig/getConstraintDefinitionQueries.js +1 -6
- package/dist/TableConfig/getConstraintDefinitionQueries.js.map +1 -1
- package/dist/TableConfig/getFutureTableSchema.d.ts.map +1 -1
- package/dist/TableConfig/getFutureTableSchema.js +16 -28
- package/dist/TableConfig/getFutureTableSchema.js.map +1 -1
- package/dist/TableConfig/getTableColumnQueries.d.ts.map +1 -1
- package/dist/TableConfig/getTableColumnQueries.js +5 -9
- package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
- package/dist/TableConfig/initTableConfig.d.ts.map +1 -1
- package/dist/TableConfig/initTableConfig.js +22 -25
- package/dist/TableConfig/initTableConfig.js.map +1 -1
- package/dist/initProstgles.js +1 -1
- package/dist/initProstgles.js.map +1 -1
- package/dist/onSocketConnected.d.ts.map +1 -1
- package/dist/onSocketConnected.js +2 -4
- package/dist/onSocketConnected.js.map +1 -1
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +14 -13
- package/dist/runClientRequest.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +114 -135
- package/lib/Auth/AuthTypes.ts +96 -81
- package/lib/Auth/authProviders/setEmailProvider.ts +29 -0
- package/lib/Auth/authProviders/setOAuthProviders.ts +97 -0
- package/lib/Auth/endpoints/getConfirmEmailRequestHandler.ts +39 -0
- package/lib/Auth/endpoints/getRegisterRequestHandler.ts +88 -0
- package/lib/Auth/setAuthProviders.ts +8 -111
- package/lib/Auth/setupAuthRoutes.ts +105 -148
- package/lib/Auth/utils/checkDmarc.ts +19 -0
- package/lib/Auth/utils/getClientRequestIPsInfo.ts +25 -0
- package/lib/Auth/utils/getReturnUrl.ts +13 -0
- package/lib/DBEventsManager.ts +12 -26
- package/lib/DBSchemaBuilder.ts +1 -1
- package/lib/DboBuilder/DboBuilder.ts +23 -52
- package/lib/DboBuilder/DboBuilderTypes.ts +9 -23
- package/lib/DboBuilder/QueryBuilder/Functions.ts +86 -188
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +11 -36
- package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +102 -129
- package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +14 -27
- package/lib/DboBuilder/QueryStreamer.ts +26 -57
- package/lib/DboBuilder/TableHandler/DataValidator.ts +58 -90
- package/lib/DboBuilder/TableHandler/TableHandler.ts +19 -45
- package/lib/DboBuilder/TableHandler/delete.ts +9 -18
- package/lib/DboBuilder/TableHandler/insert.ts +18 -31
- package/lib/DboBuilder/TableHandler/insertTest.ts +1 -1
- package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +8 -19
- package/lib/DboBuilder/TableHandler/update.ts +17 -46
- package/lib/DboBuilder/TableHandler/updateFile.ts +18 -21
- package/lib/DboBuilder/TableHandler/upsert.ts +7 -24
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +13 -15
- package/lib/DboBuilder/ViewHandler/count.ts +1 -1
- package/lib/DboBuilder/ViewHandler/find.ts +28 -35
- package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +8 -30
- package/lib/DboBuilder/ViewHandler/getInfo.ts +2 -2
- package/lib/DboBuilder/ViewHandler/getTableJoinQuery.ts +16 -32
- package/lib/DboBuilder/ViewHandler/parseFieldFilter.ts +9 -16
- package/lib/DboBuilder/ViewHandler/parseJoinPath.ts +26 -44
- package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +58 -82
- package/lib/DboBuilder/ViewHandler/prepareWhere.ts +14 -27
- package/lib/DboBuilder/dboBuilderUtils.ts +19 -46
- package/lib/DboBuilder/getColumns.ts +24 -46
- package/lib/DboBuilder/getCondition.ts +18 -30
- package/lib/DboBuilder/getSubscribeRelatedTables.ts +2 -2
- package/lib/DboBuilder/getTablesForSchemaPostgresSQL.ts +44 -62
- package/lib/DboBuilder/insertNestedRecords.ts +67 -135
- package/lib/DboBuilder/parseUpdateRules.ts +1 -1
- package/lib/DboBuilder/prepareShortestJoinPaths.ts +23 -58
- package/lib/DboBuilder/runSQL.ts +41 -76
- package/lib/DboBuilder/uploadFile.ts +26 -37
- package/lib/FileManager/FileManager.ts +27 -58
- package/lib/FileManager/initFileManager.ts +68 -76
- package/lib/FileManager/uploadStream.ts +2 -2
- package/lib/Filtering.ts +30 -87
- package/lib/JSONBValidation/validation.ts +36 -75
- package/lib/Logging.ts +1 -1
- package/lib/PostgresNotifListenManager.ts +11 -35
- package/lib/Prostgles.ts +42 -100
- package/lib/PubSubManager/PubSubManager.ts +30 -66
- package/lib/PubSubManager/addSub.ts +11 -18
- package/lib/PubSubManager/addSync.ts +5 -12
- package/lib/PubSubManager/getCreatePubSubManagerError.ts +9 -9
- package/lib/PubSubManager/initPubSubManager.ts +7 -13
- package/lib/PubSubManager/pushSubData.ts +1 -7
- package/lib/PublishParser/PublishParser.ts +8 -12
- package/lib/PublishParser/getFileTableRules.ts +1 -1
- package/lib/PublishParser/getSchemaFromPublish.ts +26 -42
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +22 -37
- package/lib/RestApi.ts +4 -12
- package/lib/SchemaWatch/SchemaWatch.ts +11 -24
- package/lib/SyncReplication.ts +96 -190
- package/lib/TableConfig/TableConfig.ts +16 -38
- package/lib/TableConfig/getConstraintDefinitionQueries.ts +2 -8
- package/lib/TableConfig/getFutureTableSchema.ts +20 -34
- package/lib/TableConfig/getTableColumnQueries.ts +13 -35
- package/lib/TableConfig/initTableConfig.ts +40 -64
- package/lib/initProstgles.ts +1 -1
- package/lib/onSocketConnected.ts +8 -12
- package/lib/runClientRequest.ts +31 -54
- package/package.json +2 -2
- package/dist/Auth/getSafeReturnURL.d.ts.map +0 -1
- package/dist/Auth/getSafeReturnURL.js.map +0 -1
- package/dist/Auth/setEmailProvider.d.ts.map +0 -1
- package/dist/Auth/setEmailProvider.js +0 -133
- package/dist/Auth/setEmailProvider.js.map +0 -1
- package/dist/DboBuilder/runTransaction.d.ts +0 -9
- package/dist/DboBuilder/runTransaction.d.ts.map +0 -1
- package/dist/DboBuilder/runTransaction.js +0 -49
- package/dist/DboBuilder/runTransaction.js.map +0 -1
- package/lib/Auth/setEmailProvider.ts +0 -132
- package/lib/DboBuilder/QueryBuilder/prepareHaving.ts +0 -27
- package/lib/DboBuilder/runTransaction.ts +0 -61
- package/lib/SchemaWatch/createSchemaWatchEventTrigger.ts +0 -3
- /package/dist/Auth/{getSafeReturnURL.d.ts → utils/getSafeReturnURL.d.ts} +0 -0
- /package/dist/Auth/{getSafeReturnURL.js → utils/getSafeReturnURL.js} +0 -0
- /package/lib/Auth/{getSafeReturnURL.ts → utils/getSafeReturnURL.ts} +0 -0
package/lib/Auth/AuthTypes.ts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
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,
|
|
21
|
+
AuthFailure,
|
|
9
22
|
} from "prostgles-types";
|
|
10
|
-
import { DB } from "../Prostgles";
|
|
11
23
|
import { DBOFullyTyped } from "../DBSchemaBuilder";
|
|
12
24
|
import { PRGLIOSocket } from "../DboBuilder/DboBuilderTypes";
|
|
13
|
-
import
|
|
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";
|
|
25
|
+
import { DB } from "../Prostgles";
|
|
25
26
|
|
|
26
27
|
type Awaitable<T> = T | Promise<T>;
|
|
27
28
|
|
|
@@ -96,54 +97,55 @@ export type Email = {
|
|
|
96
97
|
|
|
97
98
|
type EmailWithoutTo = Omit<Email, "to">;
|
|
98
99
|
|
|
99
|
-
type
|
|
100
|
+
type MagicLinkAuthResponse =
|
|
101
|
+
| AuthResponse.MagicLinkAuthFailure["code"]
|
|
102
|
+
| { response: AuthResponse.MagicLinkAuthSuccess; email: EmailWithoutTo };
|
|
103
|
+
|
|
104
|
+
type PasswordRegisterResponse =
|
|
105
|
+
| AuthResponse.PasswordRegisterFailure["code"]
|
|
106
|
+
| { response: AuthResponse.PasswordRegisterSuccess; email: EmailWithoutTo };
|
|
107
|
+
|
|
108
|
+
export type EmailProvider =
|
|
100
109
|
| {
|
|
101
110
|
signupType: "withMagicLink";
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}) => EmailWithoutTo | Promise<EmailWithoutTo>;
|
|
110
|
-
smtp: SMTPConfig;
|
|
111
|
-
};
|
|
111
|
+
onRegister: (data: {
|
|
112
|
+
email: string;
|
|
113
|
+
magicLinkUrlPath: string;
|
|
114
|
+
clientInfo: LoginClientInfo;
|
|
115
|
+
req: ExpressReq;
|
|
116
|
+
}) => Awaitable<MagicLinkAuthResponse>;
|
|
117
|
+
smtp: SMTPConfig;
|
|
112
118
|
}
|
|
113
119
|
| {
|
|
120
|
+
/**
|
|
121
|
+
* Users have to provide an email and a password.
|
|
122
|
+
* Account should be activated after email confirmation
|
|
123
|
+
*/
|
|
114
124
|
signupType: "withPassword";
|
|
115
|
-
onRegistered: (
|
|
116
|
-
data: { username: string; password: string },
|
|
117
|
-
clientInfo: LoginClientInfo
|
|
118
|
-
) => Awaitable<EmailRegisterResponse>;
|
|
119
125
|
/**
|
|
120
126
|
* Defaults to 8
|
|
121
127
|
*/
|
|
122
128
|
minPasswordLength?: number;
|
|
123
129
|
/**
|
|
124
|
-
*
|
|
130
|
+
* Called when the user has registered
|
|
125
131
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
clientInfo: LoginClientInfo;
|
|
144
|
-
req: ExpressReq;
|
|
145
|
-
}) => void | Promise<void>;
|
|
146
|
-
};
|
|
132
|
+
onRegister: (data: {
|
|
133
|
+
email: string;
|
|
134
|
+
password: string;
|
|
135
|
+
confirmationUrlPath: string;
|
|
136
|
+
clientInfo: LoginClientInfo;
|
|
137
|
+
req: ExpressReq;
|
|
138
|
+
}) => Awaitable<PasswordRegisterResponse>;
|
|
139
|
+
smtp: SMTPConfig;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Called after the user has clicked the URL to confirm their email address
|
|
143
|
+
*/
|
|
144
|
+
onEmailConfirmation: (data: {
|
|
145
|
+
confirmationCode: string;
|
|
146
|
+
clientInfo: LoginClientInfo;
|
|
147
|
+
req: ExpressReq;
|
|
148
|
+
}) => Awaitable<AuthFailure["code"] | AuthResponse.AuthSuccess>;
|
|
147
149
|
};
|
|
148
150
|
|
|
149
151
|
export type AuthProviderUserData =
|
|
@@ -242,7 +244,7 @@ export type AuthResult<SU = SessionUser> =
|
|
|
242
244
|
| {
|
|
243
245
|
user?: undefined;
|
|
244
246
|
clientUser?: undefined;
|
|
245
|
-
sid?: string;
|
|
247
|
+
sid?: string | undefined;
|
|
246
248
|
}
|
|
247
249
|
| undefined;
|
|
248
250
|
|
|
@@ -260,9 +262,14 @@ export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
|
|
|
260
262
|
sidKeyName?: string;
|
|
261
263
|
|
|
262
264
|
/**
|
|
263
|
-
*
|
|
265
|
+
* undefined sid is allowed to enable public users
|
|
264
266
|
*/
|
|
265
|
-
|
|
267
|
+
getUser: (
|
|
268
|
+
sid: string | undefined,
|
|
269
|
+
dbo: DBOFullyTyped<S>,
|
|
270
|
+
db: DB,
|
|
271
|
+
client: AuthClientRequest & LoginClientInfo
|
|
272
|
+
) => Awaitable<AuthResult<SUser>>;
|
|
266
273
|
|
|
267
274
|
/**
|
|
268
275
|
* Will setup auth routes
|
|
@@ -272,16 +279,6 @@ export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
|
|
|
272
279
|
*/
|
|
273
280
|
expressConfig?: ExpressConfig<S, SUser>;
|
|
274
281
|
|
|
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
282
|
login?: (
|
|
286
283
|
params: LoginParams,
|
|
287
284
|
dbo: DBOFullyTyped<S>,
|
|
@@ -290,18 +287,33 @@ export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
|
|
|
290
287
|
) => Awaitable<LoginResponse>;
|
|
291
288
|
logout?: (sid: string | undefined, dbo: DBOFullyTyped<S>, db: DB) => Awaitable<any>;
|
|
292
289
|
|
|
290
|
+
/**
|
|
291
|
+
* 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
|
|
292
|
+
*/
|
|
293
|
+
responseThrottle?: number;
|
|
294
|
+
|
|
293
295
|
/**
|
|
294
296
|
* If provided then session info will be saved on socket.__prglCache and reused from there
|
|
295
297
|
*/
|
|
296
298
|
cacheSession?: {
|
|
297
|
-
getSession: (
|
|
299
|
+
getSession: (
|
|
300
|
+
sid: string | undefined,
|
|
301
|
+
dbo: DBOFullyTyped<S>,
|
|
302
|
+
db: DB
|
|
303
|
+
) => Awaitable<BasicSession | undefined>;
|
|
298
304
|
};
|
|
299
305
|
};
|
|
300
306
|
|
|
301
|
-
export type LoginResponse =
|
|
307
|
+
export type LoginResponse =
|
|
308
|
+
| {
|
|
309
|
+
session: BasicSession;
|
|
310
|
+
response?: AuthResponse.PasswordLoginSuccess | AuthResponse.MagicLinkAuthSuccess;
|
|
311
|
+
}
|
|
312
|
+
| AuthResponse.PasswordLoginFailure["code"]
|
|
313
|
+
| AuthResponse.MagicLinkAuthFailure["code"];
|
|
302
314
|
|
|
303
315
|
export type LoginParams =
|
|
304
|
-
| { type: "username"
|
|
316
|
+
| ({ type: "username" } & AuthRequest.LoginData)
|
|
305
317
|
| ({ type: "provider" } & AuthProviderUserData);
|
|
306
318
|
|
|
307
319
|
type ExpressConfig<S, SUser extends SessionUser> = {
|
|
@@ -336,22 +348,25 @@ type ExpressConfig<S, SUser extends SessionUser> = {
|
|
|
336
348
|
* Will be called after a GET request is authorised
|
|
337
349
|
* This means that
|
|
338
350
|
*/
|
|
339
|
-
onGetRequestOK?: (
|
|
351
|
+
onGetRequestOK?: (
|
|
352
|
+
req: ExpressReq,
|
|
353
|
+
res: ExpressRes,
|
|
354
|
+
params: AuthRequestParams<S, SUser>
|
|
355
|
+
) => Awaitable<void>;
|
|
340
356
|
|
|
341
357
|
/**
|
|
342
|
-
* If defined, will
|
|
358
|
+
* If defined, will enable GET /magic-link/:id route.
|
|
359
|
+
* Requests with valid magic link ids will be logged in and redirected to the returnUrl if set
|
|
343
360
|
*/
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
) => Awaitable<BasicSession | undefined>;
|
|
354
|
-
};
|
|
361
|
+
onMagicLink?: (
|
|
362
|
+
magicId: string,
|
|
363
|
+
dbo: DBOFullyTyped<S>,
|
|
364
|
+
db: DB,
|
|
365
|
+
client: LoginClientInfo
|
|
366
|
+
) => Awaitable<
|
|
367
|
+
| { session: BasicSession; response?: AuthResponse.MagicLinkAuthSuccess }
|
|
368
|
+
| { session?: undefined; response: AuthResponse.MagicLinkAuthFailure }
|
|
369
|
+
>;
|
|
355
370
|
|
|
356
371
|
registrations?: AuthRegistrationConfig<S>;
|
|
357
372
|
};
|
|
@@ -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,88 @@
|
|
|
1
|
+
import { Request, Response } 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 errCodeOrResult =
|
|
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
|
+
|
|
61
|
+
const registrationResult =
|
|
62
|
+
typeof errCodeOrResult === "string" ?
|
|
63
|
+
{ email: undefined, response: { success: false as const, code: errCodeOrResult } }
|
|
64
|
+
: errCodeOrResult;
|
|
65
|
+
if (!registrationResult.email) {
|
|
66
|
+
return sendResponse(registrationResult.response);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const emailMessage = { ...registrationResult.email, to: username };
|
|
70
|
+
await sendEmail(smtp, emailMessage);
|
|
71
|
+
return sendResponse({
|
|
72
|
+
...registrationResult.response,
|
|
73
|
+
message:
|
|
74
|
+
emailAuthConfig.signupType === "withPassword" ?
|
|
75
|
+
`We've sent a confirmation email to ${emailMessage.to}. Please check your inbox (and your spam folder) for a message from us.`
|
|
76
|
+
: "Email sent",
|
|
77
|
+
});
|
|
78
|
+
} catch {
|
|
79
|
+
return sendResponse({
|
|
80
|
+
success: false,
|
|
81
|
+
code: "server-error",
|
|
82
|
+
message: "Failed to send email",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return registerRequestHandler;
|
|
88
|
+
};
|
|
@@ -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
|
|
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
|
|
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;
|