@friggframework/core 2.0.0--canary.397.fe6d7a2.0 → 2.0.0--canary.405.91dae19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +50 -931
  2. package/core/create-handler.js +0 -1
  3. package/encrypt/encrypt.js +4 -27
  4. package/handlers/app-handler-helpers.js +3 -0
  5. package/handlers/backend-utils.js +44 -42
  6. package/handlers/routers/HEALTHCHECK.md +240 -0
  7. package/handlers/routers/auth.js +14 -3
  8. package/handlers/routers/health.js +451 -0
  9. package/handlers/routers/health.test.js +203 -0
  10. package/handlers/routers/integration-defined-routers.js +5 -8
  11. package/handlers/routers/middleware/loadUser.js +15 -0
  12. package/handlers/routers/middleware/requireLoggedInUser.js +12 -0
  13. package/handlers/routers/user.js +5 -25
  14. package/handlers/workers/integration-defined-workers.js +3 -6
  15. package/index.js +16 -1
  16. package/integrations/create-frigg-backend.js +31 -0
  17. package/integrations/index.js +5 -0
  18. package/integrations/integration-base.js +46 -142
  19. package/integrations/integration-factory.js +251 -0
  20. package/integrations/integration-router.js +181 -303
  21. package/integrations/integration-user.js +144 -0
  22. package/integrations/options.js +1 -1
  23. package/integrations/test/integration-base.test.js +144 -0
  24. package/module-plugin/auther.js +393 -0
  25. package/module-plugin/entity-manager.js +70 -0
  26. package/{modules → module-plugin}/entity.js +0 -1
  27. package/{modules → module-plugin}/index.js +8 -0
  28. package/module-plugin/manager.js +169 -0
  29. package/module-plugin/module-factory.js +61 -0
  30. package/{modules → module-plugin}/test/mock-api/api.js +3 -8
  31. package/{modules → module-plugin}/test/mock-api/definition.js +8 -12
  32. package/package.json +5 -5
  33. package/syncs/sync.js +1 -0
  34. package/types/integrations/index.d.ts +6 -2
  35. package/types/module-plugin/index.d.ts +56 -4
  36. package/types/syncs/index.d.ts +2 -0
  37. package/credential/credential-repository.js +0 -56
  38. package/credential/use-cases/get-credential-for-user.js +0 -21
  39. package/credential/use-cases/update-authentication-status.js +0 -15
  40. package/handlers/app-definition-loader.js +0 -38
  41. package/integrations/integration-repository.js +0 -80
  42. package/integrations/tests/doubles/dummy-integration-class.js +0 -90
  43. package/integrations/tests/doubles/test-integration-repository.js +0 -89
  44. package/integrations/tests/use-cases/create-integration.test.js +0 -124
  45. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -143
  46. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -143
  47. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -169
  48. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -169
  49. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
  50. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
  51. package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
  52. package/integrations/tests/use-cases/update-integration.test.js +0 -134
  53. package/integrations/use-cases/create-integration.js +0 -71
  54. package/integrations/use-cases/delete-integration-for-user.js +0 -72
  55. package/integrations/use-cases/get-integration-for-user.js +0 -78
  56. package/integrations/use-cases/get-integration-instance-by-definition.js +0 -67
  57. package/integrations/use-cases/get-integration-instance.js +0 -82
  58. package/integrations/use-cases/get-integrations-for-user.js +0 -76
  59. package/integrations/use-cases/get-possible-integrations.js +0 -27
  60. package/integrations/use-cases/index.js +0 -11
  61. package/integrations/use-cases/update-integration-messages.js +0 -31
  62. package/integrations/use-cases/update-integration-status.js +0 -28
  63. package/integrations/use-cases/update-integration.js +0 -91
  64. package/integrations/utils/map-integration-dto.js +0 -36
  65. package/modules/module-factory.js +0 -54
  66. package/modules/module-repository.js +0 -107
  67. package/modules/module.js +0 -218
  68. package/modules/tests/doubles/test-module-factory.js +0 -16
  69. package/modules/tests/doubles/test-module-repository.js +0 -19
  70. package/modules/use-cases/get-entities-for-user.js +0 -32
  71. package/modules/use-cases/get-entity-options-by-id.js +0 -58
  72. package/modules/use-cases/get-entity-options-by-type.js +0 -34
  73. package/modules/use-cases/get-module-instance-from-type.js +0 -31
  74. package/modules/use-cases/get-module.js +0 -56
  75. package/modules/use-cases/process-authorization-callback.js +0 -108
  76. package/modules/use-cases/refresh-entity-options.js +0 -58
  77. package/modules/use-cases/test-module-auth.js +0 -54
  78. package/modules/utils/map-module-dto.js +0 -18
  79. package/user/tests/doubles/test-user-repository.js +0 -72
  80. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  81. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  82. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  83. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  84. package/user/tests/use-cases/login-user.test.js +0 -140
  85. package/user/use-cases/create-individual-user.js +0 -61
  86. package/user/use-cases/create-organization-user.js +0 -47
  87. package/user/use-cases/create-token-for-user-id.js +0 -30
  88. package/user/use-cases/get-user-from-bearer-token.js +0 -77
  89. package/user/use-cases/login-user.js +0 -122
  90. package/user/user-repository.js +0 -62
  91. package/user/user.js +0 -77
  92. /package/{modules → module-plugin}/ModuleConstants.js +0 -0
  93. /package/{modules → module-plugin}/credential.js +0 -0
  94. /package/{modules → module-plugin}/requester/api-key.js +0 -0
  95. /package/{modules → module-plugin}/requester/basic.js +0 -0
  96. /package/{modules → module-plugin}/requester/oauth-2.js +0 -0
  97. /package/{modules → module-plugin}/requester/requester.js +0 -0
  98. /package/{modules → module-plugin}/requester/requester.test.js +0 -0
  99. /package/{modules → module-plugin}/test/auther.test.js +0 -0
  100. /package/{modules → module-plugin}/test/mock-api/mocks/hubspot.js +0 -0
@@ -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 };
@@ -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