@friggframework/core 2.0.0--canary.395.65f5f64.0 → 2.0.0--canary.398.24926ac.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 (97) hide show
  1. package/README.md +50 -931
  2. package/core/create-handler.js +0 -1
  3. package/database/models/WebsocketConnection.js +5 -0
  4. package/handlers/app-handler-helpers.js +3 -0
  5. package/handlers/backend-utils.js +44 -42
  6. package/handlers/routers/auth.js +14 -3
  7. package/handlers/routers/integration-defined-routers.js +5 -8
  8. package/handlers/routers/middleware/loadUser.js +15 -0
  9. package/handlers/routers/middleware/requireLoggedInUser.js +12 -0
  10. package/handlers/routers/user.js +5 -25
  11. package/handlers/workers/integration-defined-workers.js +3 -6
  12. package/index.js +16 -1
  13. package/integrations/create-frigg-backend.js +31 -0
  14. package/integrations/index.js +5 -0
  15. package/integrations/integration-base.js +46 -142
  16. package/integrations/integration-factory.js +251 -0
  17. package/integrations/integration-router.js +181 -303
  18. package/integrations/integration-user.js +144 -0
  19. package/integrations/options.js +1 -1
  20. package/integrations/test/integration-base.test.js +144 -0
  21. package/module-plugin/auther.js +393 -0
  22. package/module-plugin/entity-manager.js +70 -0
  23. package/{modules → module-plugin}/entity.js +0 -1
  24. package/{modules → module-plugin}/index.js +8 -0
  25. package/module-plugin/manager.js +169 -0
  26. package/module-plugin/module-factory.js +61 -0
  27. package/{modules → module-plugin}/test/mock-api/api.js +3 -8
  28. package/{modules → module-plugin}/test/mock-api/definition.js +8 -12
  29. package/package.json +5 -5
  30. package/syncs/sync.js +1 -0
  31. package/types/integrations/index.d.ts +6 -2
  32. package/types/module-plugin/index.d.ts +56 -4
  33. package/types/syncs/index.d.ts +2 -0
  34. package/credential/credential-repository.js +0 -56
  35. package/credential/use-cases/get-credential-for-user.js +0 -21
  36. package/credential/use-cases/update-authentication-status.js +0 -15
  37. package/handlers/app-definition-loader.js +0 -38
  38. package/integrations/integration-repository.js +0 -80
  39. package/integrations/tests/doubles/dummy-integration-class.js +0 -90
  40. package/integrations/tests/doubles/test-integration-repository.js +0 -89
  41. package/integrations/tests/use-cases/create-integration.test.js +0 -124
  42. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -143
  43. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -143
  44. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -169
  45. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -169
  46. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
  47. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
  48. package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
  49. package/integrations/tests/use-cases/update-integration.test.js +0 -134
  50. package/integrations/use-cases/create-integration.js +0 -71
  51. package/integrations/use-cases/delete-integration-for-user.js +0 -72
  52. package/integrations/use-cases/get-integration-for-user.js +0 -78
  53. package/integrations/use-cases/get-integration-instance-by-definition.js +0 -67
  54. package/integrations/use-cases/get-integration-instance.js +0 -82
  55. package/integrations/use-cases/get-integrations-for-user.js +0 -76
  56. package/integrations/use-cases/get-possible-integrations.js +0 -27
  57. package/integrations/use-cases/index.js +0 -11
  58. package/integrations/use-cases/update-integration-messages.js +0 -31
  59. package/integrations/use-cases/update-integration-status.js +0 -28
  60. package/integrations/use-cases/update-integration.js +0 -91
  61. package/integrations/utils/map-integration-dto.js +0 -36
  62. package/modules/module-factory.js +0 -54
  63. package/modules/module-repository.js +0 -107
  64. package/modules/module.js +0 -218
  65. package/modules/tests/doubles/test-module-factory.js +0 -16
  66. package/modules/tests/doubles/test-module-repository.js +0 -19
  67. package/modules/use-cases/get-entities-for-user.js +0 -32
  68. package/modules/use-cases/get-entity-options-by-id.js +0 -58
  69. package/modules/use-cases/get-entity-options-by-type.js +0 -34
  70. package/modules/use-cases/get-module-instance-from-type.js +0 -31
  71. package/modules/use-cases/get-module.js +0 -56
  72. package/modules/use-cases/process-authorization-callback.js +0 -108
  73. package/modules/use-cases/refresh-entity-options.js +0 -58
  74. package/modules/use-cases/test-module-auth.js +0 -54
  75. package/modules/utils/map-module-dto.js +0 -18
  76. package/user/tests/doubles/test-user-repository.js +0 -72
  77. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  78. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  79. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  80. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  81. package/user/tests/use-cases/login-user.test.js +0 -140
  82. package/user/use-cases/create-individual-user.js +0 -61
  83. package/user/use-cases/create-organization-user.js +0 -47
  84. package/user/use-cases/create-token-for-user-id.js +0 -30
  85. package/user/use-cases/get-user-from-bearer-token.js +0 -77
  86. package/user/use-cases/login-user.js +0 -122
  87. package/user/user-repository.js +0 -62
  88. package/user/user.js +0 -77
  89. /package/{modules → module-plugin}/ModuleConstants.js +0 -0
  90. /package/{modules → module-plugin}/credential.js +0 -0
  91. /package/{modules → module-plugin}/requester/api-key.js +0 -0
  92. /package/{modules → module-plugin}/requester/basic.js +0 -0
  93. /package/{modules → module-plugin}/requester/oauth-2.js +0 -0
  94. /package/{modules → module-plugin}/requester/requester.js +0 -0
  95. /package/{modules → module-plugin}/requester/requester.test.js +0 -0
  96. /package/{modules → module-plugin}/test/auther.test.js +0 -0
  97. /package/{modules → module-plugin}/test/mock-api/mocks/hubspot.js +0 -0
package/modules/module.js DELETED
@@ -1,218 +0,0 @@
1
- const { Delegate } = require('../core');
2
- const _ = require('lodash');
3
- const { flushDebugLog } = require('../logs');
4
- const { ModuleConstants } = require('./ModuleConstants');
5
- const { CredentialRepository } = require('../credential/credential-repository');
6
- const { ModuleRepository } = require('./module-repository');
7
-
8
- // todo: this class should be a Domain class, and the Delegate function is preventing us from
9
- // doing that, we probably have to get rid of the Delegate class as well as the event based
10
- // calls since they go against the Domain Driven Design principles (eg. a domain class should not call repository methods or use cases)
11
- class Module extends Delegate {
12
-
13
- //todo: entity should be replaced with actual entity properties
14
- /**
15
- *
16
- * @param {Object} params
17
- * @param {Object} params.definition The definition of the Api Module
18
- * @param {string} params.userId The user id
19
- * @param {Object} params.entity The entity record from the database
20
- */
21
- constructor({ definition, userId = null, entity: entityObj = null }) {
22
- super({ definition, userId, entity: entityObj });
23
-
24
- this.validateDefinition(definition);
25
-
26
- this.userId = userId;
27
- this.entity = entityObj;
28
- this.credential = entityObj?.credential;
29
- this.definition = definition;
30
- this.name = this.definition.moduleName;
31
- this.modelName = this.definition.modelName;
32
- this.apiClass = this.definition.API;
33
-
34
- this.credentialRepository = new CredentialRepository();
35
- this.moduleRepository = new ModuleRepository();
36
-
37
- Object.assign(this, this.definition.requiredAuthMethods);
38
-
39
- const apiParams = {
40
- ...this.definition.env,
41
- delegate: this,
42
- ...this.apiParamsFromCredential(this.credential),
43
- ...this.apiParamsFromEntity(this.entity),
44
- };
45
- this.api = new this.apiClass(apiParams);
46
- }
47
-
48
- getName() {
49
- return this.name;
50
- }
51
-
52
- getEntityOptions() {
53
- return this.definition.getEntityOptions()
54
- }
55
-
56
- async refreshEntityOptions(options) {
57
- await this.definition.refreshEntityOptions(options);
58
- return this.getEntityOptions();
59
- }
60
-
61
- apiParamsFromCredential(credential) {
62
- return _.pick(credential, ...this.apiPropertiesToPersist?.credential);
63
- }
64
-
65
- apiParamsFromEntity(entity) {
66
- return _.pick(entity, ...this.apiPropertiesToPersist?.entity);
67
- }
68
-
69
- validateAuthorizationRequirements() {
70
- const requirements = this.getAuthorizationRequirements();
71
- let valid = true;
72
- if (
73
- ['oauth1', 'oauth2'].includes(requirements.type) &&
74
- !requirements.url
75
- ) {
76
- valid = false;
77
- }
78
- return valid;
79
- }
80
-
81
- getAuthorizationRequirements(params) {
82
- return this.api.getAuthorizationRequirements();
83
- }
84
-
85
- async testAuth() {
86
- let validAuth = false;
87
- try {
88
- if (await this.testAuthRequest(this.api)) validAuth = true;
89
- } catch (e) {
90
- flushDebugLog(e);
91
- }
92
- return validAuth;
93
- }
94
-
95
- async onTokenUpdate() {
96
- const credentialDetails = await this.getCredentialDetails(
97
- this.api,
98
- this.userId
99
- );
100
- Object.assign(
101
- credentialDetails.details,
102
- this.apiParamsFromCredential(this.api)
103
- );
104
- credentialDetails.details.auth_is_valid = true;
105
-
106
- const persisted = await this.credentialRepository.upsertCredential(credentialDetails);
107
- this.credential = persisted;
108
- }
109
-
110
- async receiveNotification(notifier, delegateString, object = null) {
111
- if (delegateString === this.api.DLGT_TOKEN_UPDATE) {
112
- await this.onTokenUpdate();
113
- } else if (delegateString === this.api.DLGT_TOKEN_DEAUTHORIZED) {
114
- await this.deauthorize();
115
- } else if (delegateString === this.api.DLGT_INVALID_AUTH) {
116
- await this.markCredentialsInvalid();
117
- }
118
- }
119
-
120
- async markCredentialsInvalid() {
121
- if (!this.credential) return;
122
-
123
- // Persist flag change through repository – works even when the
124
- // credential object is a plain JavaScript object (lean query).
125
- const credentialId = this.credential._id || this.credential.id;
126
- if (!credentialId) return;
127
-
128
- await this.credentialRepository.updateAuthenticationStatus(
129
- credentialId,
130
- false
131
- );
132
-
133
- // Keep the in-memory snapshot consistent so that callers can read the
134
- // updated state without another fetch.
135
- this.credential.auth_is_valid = false;
136
- }
137
-
138
- async deauthorize() {
139
- this.api = new this.apiClass();
140
-
141
- // Remove persisted credential (if any)
142
- if (this.entity?.credential) {
143
- const credentialId =
144
- this.entity.credential._id || this.entity.credential.id || this.entity.credential;
145
-
146
- // Delete credential via repository
147
- await this.credentialRepository.deleteCredentialById(credentialId);
148
-
149
- // Unset credential reference on the Entity document
150
- const entityId = this.entity._id || this.entity.id;
151
- if (entityId) {
152
- await this.moduleRepository.unsetCredential(entityId);
153
- }
154
-
155
- // Keep in-memory snapshot consistent
156
- this.entity.credential = undefined;
157
- }
158
- }
159
-
160
- // todo: check if all these props are still up to date
161
- validateDefinition(definition) {
162
- if (!definition) {
163
- throw new Error('Module definition is required');
164
- }
165
- if (!definition.moduleName) {
166
- throw new Error('Module definition requires moduleName');
167
- }
168
- if (!definition.API) {
169
- throw new Error('Module definition requires API class');
170
- }
171
- if (!definition.requiredAuthMethods) {
172
- throw new Error('Module definition requires requiredAuthMethods');
173
- } else {
174
- if (
175
- definition.API.requesterType ===
176
- ModuleConstants.authType.oauth2 &&
177
- !definition.requiredAuthMethods.getToken
178
- ) {
179
- throw new Error(
180
- 'Module definition requires requiredAuthMethods.getToken'
181
- );
182
- }
183
- if (!definition.requiredAuthMethods.getEntityDetails) {
184
- throw new Error(
185
- 'Module definition requires requiredAuthMethods.getEntityDetails'
186
- );
187
- }
188
- if (!definition.requiredAuthMethods.getCredentialDetails) {
189
- throw new Error(
190
- 'Module definition requires requiredAuthMethods.getCredentialDetails'
191
- );
192
- }
193
- if (!definition.requiredAuthMethods.apiPropertiesToPersist) {
194
- throw new Error(
195
- 'Module definition requires requiredAuthMethods.apiPropertiesToPersist'
196
- );
197
- } else if (definition.Credential) {
198
- for (const prop of definition.requiredAuthMethods
199
- .apiPropertiesToPersist?.credential) {
200
- if (
201
- !definition.Credential.schema.paths.hasOwnProperty(prop)
202
- ) {
203
- throw new Error(
204
- `Module definition requires Credential schema to have property ${prop}`
205
- );
206
- }
207
- }
208
- }
209
- if (!definition.requiredAuthMethods.testAuthRequest) {
210
- throw new Error(
211
- 'Module definition requires requiredAuthMethods.testAuth'
212
- );
213
- }
214
- }
215
- }
216
- }
217
-
218
- module.exports = { Module };
@@ -1,16 +0,0 @@
1
- class TestModuleFactory {
2
- constructor() { }
3
-
4
- async getModuleInstance(entityId, userId) {
5
- // return minimal stub module with getName and api property
6
- return {
7
- getName() { return 'stubModule'; },
8
- api: {},
9
- entityId,
10
- userId,
11
- testAuth: async () => true,
12
- };
13
- }
14
- }
15
-
16
- module.exports = { TestModuleFactory };
@@ -1,19 +0,0 @@
1
- class TestModuleRepository {
2
- constructor() {
3
- this.entities = new Map();
4
- }
5
-
6
- addEntity(entity) {
7
- this.entities.set(entity.id, entity);
8
- }
9
-
10
- async findEntityById(id) {
11
- return this.entities.get(id);
12
- }
13
-
14
- async findEntitiesByIds(ids) {
15
- return ids.map((id) => this.entities.get(id));
16
- }
17
- }
18
-
19
- module.exports = { TestModuleRepository };
@@ -1,32 +0,0 @@
1
- const { Module } = require('../module');
2
- const { mapModuleClassToModuleDTO } = require('../utils/map-module-dto');
3
-
4
- class GetEntitiesForUser {
5
- constructor({ moduleRepository, moduleDefinitions }) {
6
- this.moduleRepository = moduleRepository;
7
-
8
- this.definitionMap = new Map();
9
- for (const definition of moduleDefinitions) {
10
- this.definitionMap.set(definition.moduleName, definition);
11
- }
12
- }
13
-
14
- async execute(userId) {
15
- const entities = await this.moduleRepository.findEntitiesByUserId(
16
- userId
17
- );
18
-
19
- return entities.map((entity) => {
20
- const definition = this.definitionMap.get(entity.moduleName);
21
-
22
- const moduleInstance = new Module({
23
- userId,
24
- definition: definition,
25
- entity: entity,
26
- });
27
- return mapModuleClassToModuleDTO(moduleInstance);
28
- });
29
- }
30
- }
31
-
32
- module.exports = { GetEntitiesForUser };
@@ -1,58 +0,0 @@
1
- const { Module } = require('../module');
2
-
3
- class GetEntityOptionsById {
4
- /**
5
- * @param {Object} params
6
- * @param {import('../module-repository').ModuleRepository} params.moduleRepository
7
- * @param {} params.moduleDefinitions
8
- */
9
- constructor({ moduleRepository, moduleDefinitions }) {
10
- this.moduleRepository = moduleRepository;
11
- this.moduleDefinitions = moduleDefinitions;
12
- }
13
-
14
- /**
15
- * Retrieve a Module instance for a given user and entity/module type.
16
- * @param {string} userId
17
- * @param {string} entityId
18
- */
19
- async execute(entityId, userId) {
20
- const entity = await this.moduleRepository.findEntityById(
21
- entityId,
22
- userId
23
- );
24
-
25
- if (!entity) {
26
- throw new Error(`Entity ${entityId} not found`);
27
- }
28
-
29
- if (entity.userId !== userId) {
30
- throw new Error(
31
- `Entity ${entityId} does not belong to user ${userId}`
32
- );
33
- }
34
-
35
- const entityType = entity.type;
36
- const moduleDefinition = this.moduleDefinitions.find((def) => {
37
- const modelName = Module.getEntityModelFromDefinition(def).modelName;
38
- return entityType === modelName;
39
- });
40
-
41
- if (!moduleDefinition) {
42
- throw new Error(
43
- `Module definition not found for entity type: ${entityType}`
44
- );
45
- }
46
-
47
- const module = new Module({
48
- userId,
49
- entity,
50
- definition: moduleDefinition,
51
- });
52
-
53
- const entityOptions = await module.getEntityOptions();
54
- return entityOptions;
55
- }
56
- }
57
-
58
- module.exports = { GetEntityOptionsById };
@@ -1,34 +0,0 @@
1
- const { Module } = require('../module');
2
-
3
- class GetEntityOptionsByType {
4
- /**
5
- * @param {Object} params
6
- * @param {} params.moduleDefinitions
7
- */
8
- constructor({ moduleDefinitions }) {
9
- this.moduleDefinitions = moduleDefinitions;
10
- }
11
-
12
- /**
13
- * Retrieve a Module instance for a given user and entity/module type.
14
- * @param {string} userId
15
- * @param {string} type – human-readable module/entity type (e.g. "Hubspot")
16
- */
17
- async execute(userId, type) {
18
- const moduleDefinition = this.moduleDefinitions.find(
19
- (def) => def.getName() === type
20
- );
21
- if (!moduleDefinition) {
22
- throw new Error(`Module definition not found for type: ${type}`);
23
- }
24
- const moduleInstance = new Module({
25
- userId,
26
- definition: moduleDefinition,
27
- });
28
-
29
- const entityOptions = await moduleInstance.getEntityOptions();
30
- return entityOptions;
31
- }
32
- }
33
-
34
- module.exports = { GetEntityOptionsByType };
@@ -1,31 +0,0 @@
1
- const { Module } = require('../module');
2
-
3
- class GetModuleInstanceFromType {
4
- /**
5
- * @param {Object} params
6
- * @param {} params.moduleDefinitions
7
- */
8
- constructor({ moduleDefinitions }) {
9
- this.moduleDefinitions = moduleDefinitions;
10
- }
11
-
12
- /**
13
- * Retrieve a Module instance for a given user and entity/module type.
14
- * @param {string} userId
15
- * @param {string} type – human-readable module/entity type (e.g. "Hubspot")
16
- */
17
- async execute(userId, type) {
18
- const moduleDefinition = this.moduleDefinitions.find(
19
- (def) => def.getName() === type
20
- );
21
- if (!moduleDefinition) {
22
- throw new Error(`Module definition not found for type: ${type}`);
23
- }
24
- return new Module({
25
- userId,
26
- definition: moduleDefinition,
27
- });
28
- }
29
- }
30
-
31
- module.exports = { GetModuleInstanceFromType };
@@ -1,56 +0,0 @@
1
- const { Module } = require('../module');
2
-
3
- class GetModule {
4
- constructor({ moduleRepository, moduleDefinitions }) {
5
- this.moduleRepository = moduleRepository;
6
- this.moduleDefinitions = moduleDefinitions;
7
- }
8
-
9
- async execute(entityId, userId) {
10
- const entity = await this.moduleRepository.findEntityById(
11
- entityId,
12
- userId
13
- );
14
-
15
- if (!entity) {
16
- throw new Error(`Entity ${entityId} not found`);
17
- }
18
-
19
- if (entity.userId !== userId) {
20
- throw new Error(
21
- `Entity ${entityId} does not belong to user ${userId}`
22
- );
23
- }
24
-
25
- const entityType = entity.type;
26
- const moduleDefinition = this.moduleDefinitions.find((def) => {
27
- const modelName = Module.getEntityModelFromDefinition(def).modelName;
28
- return entityType === modelName;
29
- });
30
-
31
- if (!moduleDefinition) {
32
- throw new Error(
33
- `Module definition not found for entity type: ${entityType}`
34
- );
35
- }
36
-
37
- const module = new Module({
38
- userId,
39
- entity,
40
- definition: moduleDefinition,
41
- });
42
-
43
- // todo: this properties should be methods in the Module class
44
- return {
45
- id: module.entity.id,
46
- name: module.entity.name,
47
- type: module.entity.moduleName,
48
- moduleName: module.entity.moduleName,
49
- credential: module.credential,
50
- externalId: module.entity.externalId,
51
- userId: module.entity.user.toString(),
52
- }
53
- }
54
- }
55
-
56
- module.exports = { GetModule };
@@ -1,108 +0,0 @@
1
- const { Module } = require('../module');
2
- const { ModuleConstants } = require('../ModuleConstants');
3
-
4
- class ProcessAuthorizationCallback {
5
- /**
6
- * @param {Object} params - Configuration parameters.
7
- * @param {import('../module-repository').ModuleRepository} params.moduleRepository - Repository for module data operations.
8
- * @param {import('../../credential/credential-repository').CredentialRepository} params.credentialRepository - Repository for credential data operations.
9
- * @param {Array<Object>} params.moduleDefinitions - Array of module definitions.
10
- */
11
- constructor({ moduleRepository, credentialRepository, moduleDefinitions }) {
12
- this.moduleRepository = moduleRepository;
13
- this.credentialRepository = credentialRepository;
14
- this.moduleDefinitions = moduleDefinitions;
15
- }
16
-
17
- async execute(userId, entityType, params) {
18
- const moduleDefinition = this.moduleDefinitions.find((def) => {
19
- return entityType === def.moduleName;
20
- });
21
-
22
- if (!moduleDefinition) {
23
- throw new Error(
24
- `Module definition not found for entity type: ${entityType}`
25
- );
26
- }
27
-
28
- // todo: check if we need to pass entity to Module, right now it's null
29
- let entity = null;
30
-
31
- const module = new Module({
32
- userId,
33
- entity,
34
- definition: moduleDefinition,
35
- });
36
-
37
- let tokenResponse;
38
- if (module.apiClass.requesterType === ModuleConstants.authType.oauth2) {
39
- tokenResponse = await moduleDefinition.requiredAuthMethods.getToken(module.api, params);
40
- } else {
41
- tokenResponse = await moduleDefinition.requiredAuthMethods.setAuthParams(module.api, params);
42
- await this.onTokenUpdate(module, moduleDefinition, userId);
43
- }
44
-
45
- const authRes = await module.testAuth();
46
- if (!authRes) {
47
- throw new Error('Authorization failed');
48
- }
49
-
50
- const entityDetails = await moduleDefinition.requiredAuthMethods.getEntityDetails(
51
- module.api,
52
- params,
53
- tokenResponse,
54
- userId
55
- );
56
-
57
- Object.assign(
58
- entityDetails.details,
59
- module.apiParamsFromEntity(module.api)
60
- );
61
-
62
- const persistedEntity = await this.findOrCreateEntity(entityDetails, entityType, module.credential.id);
63
-
64
- return {
65
- credential_id: module.credential.id,
66
- entity_id: persistedEntity.id,
67
- type: module.getName(),
68
- };
69
- }
70
-
71
- async onTokenUpdate(module, moduleDefinition, userId) {
72
- const credentialDetails = await moduleDefinition.requiredAuthMethods.getCredentialDetails(
73
- module.api,
74
- userId
75
- );
76
-
77
- Object.assign(
78
- credentialDetails.details,
79
- module.apiParamsFromCredential(module.api)
80
- );
81
- credentialDetails.details.auth_is_valid = true;
82
-
83
- await this.credentialRepository.upsertCredential(credentialDetails);
84
- }
85
-
86
- async findOrCreateEntity(entityDetails, moduleName, credentialId) {
87
- const { identifiers, details } = entityDetails;
88
-
89
- const existingEntity = await this.moduleRepository.findEntity({
90
- externalId: identifiers.externalId,
91
- user: identifiers.user,
92
- moduleName: moduleName,
93
- });
94
-
95
- if (existingEntity) {
96
- return existingEntity;
97
- }
98
-
99
- return await this.moduleRepository.createEntity({
100
- ...identifiers,
101
- ...details,
102
- moduleName: moduleName,
103
- credential: credentialId
104
- });
105
- }
106
- }
107
-
108
- module.exports = { ProcessAuthorizationCallback };
@@ -1,58 +0,0 @@
1
- const { Module } = require('../module');
2
-
3
- class RefreshEntityOptions {
4
- /**
5
- * @param {Object} params
6
- * @param {import('../module-repository').ModuleRepository} params.moduleRepository
7
- * @param {} params.moduleDefinitions
8
- */
9
- constructor({ moduleRepository, moduleDefinitions }) {
10
- this.moduleRepository = moduleRepository;
11
- this.moduleDefinitions = moduleDefinitions;
12
- }
13
-
14
- /**
15
- * Retrieve a Module instance for a given user and entity/module type.
16
- * @param {string} userId
17
- * @param {string} entityId
18
- */
19
- async execute(entityId, userId, options) {
20
- const entity = await this.moduleRepository.findEntityById(
21
- entityId,
22
- userId
23
- );
24
-
25
- if (!entity) {
26
- throw new Error(`Entity ${entityId} not found`);
27
- }
28
-
29
- if (entity.userId !== userId) {
30
- throw new Error(
31
- `Entity ${entityId} does not belong to user ${userId}`
32
- );
33
- }
34
-
35
- const entityType = entity.type;
36
- const moduleDefinition = this.moduleDefinitions.find((def) => {
37
- const modelName = Module.getEntityModelFromDefinition(def).modelName;
38
- return entityType === modelName;
39
- });
40
-
41
- if (!moduleDefinition) {
42
- throw new Error(
43
- `Module definition not found for entity type: ${entityType}`
44
- );
45
- }
46
-
47
- const module = new Module({
48
- userId,
49
- entity,
50
- definition: moduleDefinition,
51
- });
52
-
53
- await module.refreshEntityOptions(options);
54
- return module.getEntityOptions();
55
- }
56
- }
57
-
58
- module.exports = { RefreshEntityOptions };
@@ -1,54 +0,0 @@
1
- const { Module } = require('../module');
2
-
3
- class TestModuleAuth {
4
- /**
5
- * @param {Object} params - Configuration parameters.
6
- * @param {import('./module-repository').ModuleRepository} params.moduleRepository - Repository for module data operations.
7
- * @param {Array<Object>} params.moduleDefinitions - Array of module definitions.
8
- */
9
- constructor({ moduleRepository, moduleDefinitions }) {
10
- this.moduleRepository = moduleRepository;
11
- this.moduleDefinitions = moduleDefinitions;
12
- }
13
-
14
- async execute(entityId, userId) {
15
- const entity = await this.moduleRepository.findEntityById(
16
- entityId,
17
- userId
18
- );
19
-
20
- if (!entity) {
21
- throw new Error(`Entity ${entityId} not found`);
22
- }
23
-
24
- if (entity.userId !== userId) {
25
- throw new Error(
26
- `Entity ${entityId} does not belong to user ${userId}`
27
- );
28
- }
29
-
30
- const entityType = entity.type;
31
- const moduleDefinition = this.moduleDefinitions.find((def) => {
32
- const modelName = Module.getEntityModelFromDefinition(def).modelName;
33
- return entityType === modelName;
34
- });
35
-
36
- if (!moduleDefinition) {
37
- throw new Error(
38
- `Module definition not found for entity type: ${entityType}`
39
- );
40
- }
41
-
42
- const module = new Module({
43
- userId,
44
- entity,
45
- definition: moduleDefinition,
46
- });
47
-
48
- const testAuthResponse = await module.testAuth();
49
-
50
- return testAuthResponse;
51
- }
52
- }
53
-
54
- module.exports = { TestModuleAuth };