@friggframework/core 2.0.0--canary.397.4957a89.0 → 2.0.0--canary.398.bdb6d27.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.
- package/README.md +50 -931
- package/core/create-handler.js +0 -1
- package/database/models/WebsocketConnection.js +5 -0
- package/handlers/app-handler-helpers.js +3 -0
- package/handlers/backend-utils.js +34 -35
- package/handlers/routers/auth.js +14 -3
- package/handlers/routers/integration-defined-routers.js +5 -8
- package/handlers/routers/middleware/loadUser.js +15 -0
- package/handlers/routers/middleware/requireLoggedInUser.js +12 -0
- package/handlers/routers/user.js +5 -25
- package/handlers/workers/integration-defined-workers.js +3 -6
- package/index.js +16 -1
- package/integrations/create-frigg-backend.js +31 -0
- package/integrations/index.js +5 -0
- package/integrations/integration-base.js +44 -42
- package/integrations/integration-factory.js +251 -0
- package/integrations/integration-router.js +178 -301
- package/integrations/integration-user.js +144 -0
- package/integrations/options.js +1 -1
- package/integrations/test/integration-base.test.js +144 -0
- package/module-plugin/auther.js +393 -0
- package/module-plugin/entity-manager.js +70 -0
- package/{modules → module-plugin}/index.js +8 -0
- package/module-plugin/manager.js +169 -0
- package/module-plugin/module-factory.js +61 -0
- package/{modules → module-plugin}/test/mock-api/api.js +3 -8
- package/{modules → module-plugin}/test/mock-api/definition.js +8 -12
- package/package.json +5 -5
- package/syncs/sync.js +1 -0
- package/types/integrations/index.d.ts +6 -2
- package/types/module-plugin/index.d.ts +56 -4
- package/types/syncs/index.d.ts +2 -0
- package/credential/credential-repository.js +0 -42
- package/credential/use-cases/get-credential-for-user.js +0 -21
- package/credential/use-cases/update-authentication-status.js +0 -15
- package/handlers/app-definition-loader.js +0 -38
- package/integrations/integration-repository.js +0 -67
- package/integrations/integration.js +0 -233
- package/integrations/tests/doubles/dummy-integration-class.js +0 -90
- package/integrations/tests/doubles/test-integration-repository.js +0 -89
- package/integrations/tests/use-cases/create-integration.test.js +0 -124
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -143
- package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -143
- package/integrations/tests/use-cases/get-integration-instance.test.js +0 -169
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -169
- package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
- package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
- package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
- package/integrations/tests/use-cases/update-integration.test.js +0 -134
- package/integrations/use-cases/create-integration.js +0 -72
- package/integrations/use-cases/delete-integration-for-user.js +0 -73
- package/integrations/use-cases/get-integration-for-user.js +0 -79
- package/integrations/use-cases/get-integration-instance.js +0 -84
- package/integrations/use-cases/get-integrations-for-user.js +0 -77
- package/integrations/use-cases/get-possible-integrations.js +0 -27
- package/integrations/use-cases/index.js +0 -11
- package/integrations/use-cases/update-integration-messages.js +0 -31
- package/integrations/use-cases/update-integration-status.js +0 -28
- package/integrations/use-cases/update-integration.js +0 -92
- package/integrations/utils/map-integration-dto.js +0 -36
- package/modules/module-factory.js +0 -54
- package/modules/module-repository.js +0 -107
- package/modules/module.js +0 -221
- package/modules/tests/doubles/test-module-factory.js +0 -16
- package/modules/tests/doubles/test-module-repository.js +0 -19
- package/modules/use-cases/get-entities-for-user.js +0 -32
- package/modules/use-cases/get-entity-options-by-id.js +0 -58
- package/modules/use-cases/get-entity-options-by-type.js +0 -34
- package/modules/use-cases/get-module-instance-from-type.js +0 -31
- package/modules/use-cases/get-module.js +0 -56
- package/modules/use-cases/process-authorization-callback.js +0 -114
- package/modules/use-cases/refresh-entity-options.js +0 -58
- package/modules/use-cases/test-module-auth.js +0 -54
- package/modules/utils/map-module-dto.js +0 -18
- package/user/tests/doubles/test-user-repository.js +0 -72
- package/user/tests/use-cases/create-individual-user.test.js +0 -24
- package/user/tests/use-cases/create-organization-user.test.js +0 -28
- package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
- package/user/tests/use-cases/login-user.test.js +0 -140
- package/user/use-cases/create-individual-user.js +0 -61
- package/user/use-cases/create-organization-user.js +0 -47
- package/user/use-cases/create-token-for-user-id.js +0 -30
- package/user/use-cases/get-user-from-bearer-token.js +0 -77
- package/user/use-cases/login-user.js +0 -122
- package/user/user-repository.js +0 -62
- package/user/user.js +0 -77
- /package/{modules → module-plugin}/ModuleConstants.js +0 -0
- /package/{modules → module-plugin}/credential.js +0 -0
- /package/{modules → module-plugin}/entity.js +0 -0
- /package/{modules → module-plugin}/requester/api-key.js +0 -0
- /package/{modules → module-plugin}/requester/basic.js +0 -0
- /package/{modules → module-plugin}/requester/oauth-2.js +0 -0
- /package/{modules → module-plugin}/requester/requester.js +0 -0
- /package/{modules → module-plugin}/requester/requester.test.js +0 -0
- /package/{modules → module-plugin}/test/auther.test.js +0 -0
- /package/{modules → module-plugin}/test/mock-api/mocks/hubspot.js +0 -0
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const Boom = require('@hapi/boom');
|
|
2
|
-
const { User } = require('../user');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use case for retrieving a user from a bearer token.
|
|
6
|
-
* @class GetUserFromBearerToken
|
|
7
|
-
*/
|
|
8
|
-
class GetUserFromBearerToken {
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new GetUserFromBearerToken instance.
|
|
11
|
-
* @param {Object} params - Configuration parameters.
|
|
12
|
-
* @param {import('../user-repository').UserRepository} params.userRepository - Repository for user data operations.
|
|
13
|
-
* @param {Object} params.userConfig - The user config in the app definition.
|
|
14
|
-
*/
|
|
15
|
-
constructor({ userRepository, userConfig }) {
|
|
16
|
-
this.userRepository = userRepository;
|
|
17
|
-
this.userConfig = userConfig;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Executes the use case.
|
|
22
|
-
* @async
|
|
23
|
-
* @param {string} bearerToken - The bearer token from the authorization header.
|
|
24
|
-
* @returns {Promise<import('../user').User>} The authenticated user object.
|
|
25
|
-
* @throws {Boom} 401 Unauthorized if the token is missing, malformed, or invalid.
|
|
26
|
-
*/
|
|
27
|
-
async execute(bearerToken) {
|
|
28
|
-
if (!bearerToken) {
|
|
29
|
-
throw Boom.unauthorized('Missing Authorization Header');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const token = bearerToken.split(' ')[1]?.trim();
|
|
33
|
-
if (!token) {
|
|
34
|
-
throw Boom.unauthorized('Invalid Token Format');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const sessionToken = await this.userRepository.getSessionToken(token);
|
|
38
|
-
|
|
39
|
-
if (!sessionToken) {
|
|
40
|
-
throw Boom.unauthorized('Session Token Not Found');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (this.userConfig.primary === 'organization') {
|
|
44
|
-
const organizationUserData = await this.userRepository.findOrganizationUserById(sessionToken.user);
|
|
45
|
-
|
|
46
|
-
if (!organizationUserData) {
|
|
47
|
-
throw Boom.unauthorized('Organization User Not Found');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return new User(
|
|
51
|
-
null,
|
|
52
|
-
organizationUserData,
|
|
53
|
-
this.userConfig.usePassword,
|
|
54
|
-
this.userConfig.primary,
|
|
55
|
-
this.userConfig.individualUserRequired,
|
|
56
|
-
this.userConfig.organizationUserRequired
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const individualUserData = await this.userRepository.findIndividualUserById(sessionToken.user);
|
|
61
|
-
|
|
62
|
-
if (!individualUserData) {
|
|
63
|
-
throw Boom.unauthorized('Individual User Not Found');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return new User(
|
|
67
|
-
individualUserData,
|
|
68
|
-
null,
|
|
69
|
-
this.userConfig.usePassword,
|
|
70
|
-
this.userConfig.primary,
|
|
71
|
-
this.userConfig.individualUserRequired,
|
|
72
|
-
this.userConfig.organizationUserRequired
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = { GetUserFromBearerToken };
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
const Boom = require('@hapi/boom');
|
|
2
|
-
const {
|
|
3
|
-
RequiredPropertyError,
|
|
4
|
-
} = require('../../errors');
|
|
5
|
-
const { User } = require('../user');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Use case for logging in a user.
|
|
9
|
-
* @class LoginUser
|
|
10
|
-
*/
|
|
11
|
-
class LoginUser {
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new LoginUser instance.
|
|
14
|
-
* @param {Object} params - Configuration parameters.
|
|
15
|
-
* @param {import('../user-repository').UserRepository} params.userRepository - Repository for user data operations.
|
|
16
|
-
* @param {Object} params.userConfig - The user properties inside of the app definition.
|
|
17
|
-
*/
|
|
18
|
-
constructor({ userRepository, userConfig }) {
|
|
19
|
-
this.userRepository = userRepository;
|
|
20
|
-
this.userConfig = userConfig;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Executes the use case.
|
|
25
|
-
* @async
|
|
26
|
-
* @param {Object} userCredentials - The user's credentials for authentication.
|
|
27
|
-
* @param {string} [userCredentials.username] - The username for authentication.
|
|
28
|
-
* @param {string} [userCredentials.password] - The password for authentication.
|
|
29
|
-
* @param {string} [userCredentials.appUserId] - The app user id for authentication if no username and password are provided.
|
|
30
|
-
* @param {string} [userCredentials.appOrgId] - The app organization id for authentication if no username and password are provided.
|
|
31
|
-
* @returns {Promise<import('../user').User>} The authenticated user object.
|
|
32
|
-
*/
|
|
33
|
-
async execute(userCredentials) {
|
|
34
|
-
const { username, password, appUserId, appOrgId } = userCredentials;
|
|
35
|
-
if (this.userConfig.individualUserRequired) {
|
|
36
|
-
if (this.userConfig.usePassword) {
|
|
37
|
-
if (!username) {
|
|
38
|
-
throw new RequiredPropertyError({
|
|
39
|
-
parent: this,
|
|
40
|
-
key: 'username',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (!password) {
|
|
44
|
-
throw new RequiredPropertyError({
|
|
45
|
-
parent: this,
|
|
46
|
-
key: 'password',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const individualUserData =
|
|
51
|
-
await this.userRepository.findIndividualUserByUsername(
|
|
52
|
-
username
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
if (!individualUserData) {
|
|
56
|
-
throw Boom.unauthorized('user not found');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const individualUser = new User(
|
|
60
|
-
individualUserData,
|
|
61
|
-
null,
|
|
62
|
-
this.userConfig.usePassword,
|
|
63
|
-
this.userConfig.primary,
|
|
64
|
-
this.userConfig.individualUserRequired,
|
|
65
|
-
this.userConfig.organizationUserRequired
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
if (!individualUser.isPasswordValid(password)) {
|
|
69
|
-
throw Boom.unauthorized('Incorrect username or password');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return individualUser;
|
|
73
|
-
} else {
|
|
74
|
-
const individualUserData =
|
|
75
|
-
await this.userRepository.findIndividualUserByAppUserId(
|
|
76
|
-
appUserId
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (!individualUserData) {
|
|
80
|
-
throw Boom.unauthorized('user not found');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const individualUser = new User(
|
|
84
|
-
individualUserData,
|
|
85
|
-
null,
|
|
86
|
-
this.userConfig.usePassword,
|
|
87
|
-
this.userConfig.primary,
|
|
88
|
-
this.userConfig.individualUserRequired,
|
|
89
|
-
this.userConfig.organizationUserRequired
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return individualUser;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (this.userConfig.organizationUserRequired) {
|
|
98
|
-
|
|
99
|
-
const organizationUserData =
|
|
100
|
-
await this.userRepository.findOrganizationUserByAppOrgId(appOrgId);
|
|
101
|
-
|
|
102
|
-
if (!organizationUserData) {
|
|
103
|
-
throw Boom.unauthorized(`org user ${appOrgId} not found`);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const organizationUser = new User(
|
|
107
|
-
null,
|
|
108
|
-
organizationUserData,
|
|
109
|
-
this.userConfig.usePassword,
|
|
110
|
-
this.userConfig.primary,
|
|
111
|
-
this.userConfig.individualUserRequired,
|
|
112
|
-
this.userConfig.organizationUserRequired
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return organizationUser;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
module.exports = { LoginUser };
|
package/user/user-repository.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const { Token } = require('../database/models/Token');
|
|
2
|
-
const { IndividualUser } = require('../database/models/IndividualUser');
|
|
3
|
-
const { OrganizationUser } = require('../database/models/OrganizationUser');
|
|
4
|
-
|
|
5
|
-
class UserRepository {
|
|
6
|
-
/**
|
|
7
|
-
* @param {Object} userConfig - The user config in the app definition.
|
|
8
|
-
*/
|
|
9
|
-
constructor({ userConfig }) {
|
|
10
|
-
this.IndividualUser = IndividualUser;
|
|
11
|
-
this.OrganizationUser = OrganizationUser;
|
|
12
|
-
this.Token = Token;
|
|
13
|
-
this.userConfig = userConfig;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async getSessionToken(token) {
|
|
17
|
-
const jsonToken =
|
|
18
|
-
this.Token.getJSONTokenFromBase64BufferToken(token);
|
|
19
|
-
const sessionToken =
|
|
20
|
-
await this.Token.validateAndGetTokenFromJSONToken(jsonToken);
|
|
21
|
-
return sessionToken;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async findOrganizationUserById(userId) {
|
|
25
|
-
return this.OrganizationUser.findById(userId);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async findIndividualUserById(userId) {
|
|
29
|
-
return this.IndividualUser.findById(userId);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async createToken(userId, rawToken, minutes = 120) {
|
|
33
|
-
const createdToken = await this.Token.createTokenWithExpire(
|
|
34
|
-
userId,
|
|
35
|
-
rawToken,
|
|
36
|
-
minutes
|
|
37
|
-
);
|
|
38
|
-
return this.Token.createBase64BufferToken(createdToken, rawToken);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async createIndividualUser(params) {
|
|
42
|
-
return this.IndividualUser.create(params);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async createOrganizationUser(params) {
|
|
46
|
-
return this.OrganizationUser.create(params);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async findIndividualUserByUsername(username) {
|
|
50
|
-
return this.IndividualUser.findOne({ username });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async findIndividualUserByAppUserId(appUserId) {
|
|
54
|
-
return this.IndividualUser.getUserByAppUserId(appUserId);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async findOrganizationUserByAppOrgId(appOrgId) {
|
|
58
|
-
return this.OrganizationUser.getUserByAppOrgId(appOrgId);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = { UserRepository };
|
package/user/user.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const bcrypt = require('bcryptjs');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a user in the system. The User class is a domain entity,
|
|
5
|
-
* @class User
|
|
6
|
-
*/
|
|
7
|
-
class User {
|
|
8
|
-
/**
|
|
9
|
-
* Creates a new User instance.
|
|
10
|
-
* @param {import('../database/models/IndividualUser').IndividualUser} [individualUser=null] - The individual user for the user.
|
|
11
|
-
* @param {import('../database/models/OrganizationUser').OrganizationUser} [organizationUser=null] - The organization user for the user.
|
|
12
|
-
* @param {boolean} [usePassword=false] - Whether the user has a password.
|
|
13
|
-
* @param {string} [primary='individual'] - The primary user type.
|
|
14
|
-
* @param {boolean} [individualUserRequired=true] - Whether the user is required to have an individual user.
|
|
15
|
-
* @param {boolean} [organizationUserRequired=false] - Whether the user is required to have an organization user.
|
|
16
|
-
*/
|
|
17
|
-
constructor(individualUser = null, organizationUser = null, usePassword = false, primary = 'individual', individualUserRequired = true, organizationUserRequired = false) {
|
|
18
|
-
this.individualUser = individualUser;
|
|
19
|
-
this.organizationUser = organizationUser;
|
|
20
|
-
this.usePassword = usePassword;
|
|
21
|
-
|
|
22
|
-
this.config = {
|
|
23
|
-
primary,
|
|
24
|
-
individualUserRequired,
|
|
25
|
-
organizationUserRequired,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getPrimaryUser() {
|
|
30
|
-
if (this.config.primary === 'organization') {
|
|
31
|
-
return this.organizationUser;
|
|
32
|
-
}
|
|
33
|
-
return this.individualUser;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getId() {
|
|
37
|
-
return this.getPrimaryUser()?.id;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
isPasswordRequired() {
|
|
41
|
-
return this.usePassword;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
isPasswordValid(password) {
|
|
45
|
-
if (!this.isPasswordRequired()) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return bcrypt.compareSync(password, this.getPrimaryUser().hashword);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setIndividualUser(individualUser) {
|
|
53
|
-
this.individualUser = individualUser;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setOrganizationUser(organizationUser) {
|
|
57
|
-
this.organizationUser = organizationUser;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
isOrganizationUserRequired() {
|
|
61
|
-
return this.config.organizationUserRequired;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
isIndividualUserRequired() {
|
|
65
|
-
return this.config.individualUserRequired;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getIndividualUser() {
|
|
69
|
-
return this.individualUser;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getOrganizationUser() {
|
|
73
|
-
return this.organizationUser;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = { User };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|