@friggframework/core 2.0.0--canary.396.607ab7a.0 → 2.0.0--canary.396.d50d765.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.
@@ -16,37 +16,6 @@ const {
16
16
  loadAppDefinition,
17
17
  } = require('../handlers/app-definition-loader');
18
18
 
19
-
20
- const { integrations } = loadAppDefinition();
21
- const moduleRepository = new ModuleRepository();
22
- const integrationRepository = new IntegrationRepository();
23
- const credentialRepository = new CredentialRepository();
24
- const moduleService = new ModuleService({ moduleRepository, moduleDefinitions: { ...getModules() } });
25
- const deleteIntegrationForUser = new DeleteIntegrationForUser({ integrationRepository });
26
- const getIntegrationForUser = new GetIntegrationForUser({ integrationRepository });
27
- const getIntegrationsForUser = new GetIntegrationsForUser({ integrationRepository });
28
- const getCredentialForUser = new GetCredentialForUser({ credentialRepository });
29
- const createIntegration = new CreateIntegration({
30
- integrationRepository,
31
- integrationClasses: integrations,
32
- moduleService,
33
- });
34
-
35
- // todo: move this into a utils file
36
- const getModules = () => {
37
- return [
38
- ...new Set(
39
- integrations
40
- .map((integration) =>
41
- Object.values(integration.Definition.modules).map(
42
- (module) => module.definition
43
- )
44
- )
45
- .flat()
46
- ),
47
- ];
48
- }
49
-
50
19
  // todo: dont send moduleFactory and integrationFactory as a factory object, instead send them as separate params.
51
20
  // todo: this could be a use case class
52
21
  /**
@@ -60,12 +29,59 @@ const getModules = () => {
60
29
  * @returns {express.Router} Configured Express router with integration and entity routes
61
30
  */
62
31
  function createIntegrationRouter(params) {
32
+ const { integrations } = loadAppDefinition();
33
+ const moduleRepository = new ModuleRepository();
34
+ const integrationRepository = new IntegrationRepository();
35
+ const credentialRepository = new CredentialRepository();
36
+
37
+ // todo: move this into a utils file
38
+ const getModules = () => {
39
+ return [
40
+ ...new Set(
41
+ integrations
42
+ .map((integration) =>
43
+ Object.values(integration.Definition.modules).map(
44
+ (module) => module.definition
45
+ )
46
+ )
47
+ .flat()
48
+ ),
49
+ ];
50
+ };
51
+ const moduleService = new ModuleService({
52
+ moduleRepository,
53
+ moduleDefinitions: getModules(),
54
+ });
55
+ const deleteIntegrationForUser = new DeleteIntegrationForUser({
56
+ integrationRepository,
57
+ });
58
+ const getIntegrationForUser = new GetIntegrationForUser({
59
+ integrationRepository,
60
+ });
61
+ const getIntegrationsForUser = new GetIntegrationsForUser({
62
+ integrationRepository,
63
+ });
64
+ const getCredentialForUser = new GetCredentialForUser({
65
+ credentialRepository,
66
+ });
67
+ const createIntegration = new CreateIntegration({
68
+ integrationRepository,
69
+ integrationClasses: integrations,
70
+ moduleService,
71
+ });
72
+
63
73
  const router = get(params, 'router', express());
64
74
  const factory = get(params, 'factory');
65
75
  const getUserFromBearerToken = get(params, 'getUserFromBearerToken');
66
76
 
67
- setIntegrationRoutes(router, factory, getUserFromBearerToken);
68
- setEntityRoutes(router, factory, getUserFromBearerToken);
77
+ setIntegrationRoutes(router, factory, getUserFromBearerToken, {
78
+ createIntegration,
79
+ deleteIntegrationForUser,
80
+ getIntegrationsForUser,
81
+ });
82
+ setEntityRoutes(router, factory, getUserFromBearerToken, {
83
+ getCredentialForUser,
84
+ });
69
85
  return router;
70
86
  }
71
87
 
@@ -99,8 +115,13 @@ function checkRequiredParams(params, requiredKeys) {
99
115
  * @param {Object} factory.integrationFactory - Factory for creating and managing integrations
100
116
  * @param {import('../user/use-cases/get-user-from-bearer-token').GetUserFromBearerToken} getUserFromBearerToken - Use case for retrieving a user from a bearer token
101
117
  */
102
- function setIntegrationRoutes(router, factory, getUserFromBearerToken) {
118
+ function setIntegrationRoutes(router, factory, getUserFromBearerToken, useCases) {
103
119
  const { moduleFactory, integrationFactory } = factory;
120
+ const {
121
+ createIntegration,
122
+ deleteIntegrationForUser,
123
+ getIntegrationsForUser,
124
+ } = useCases;
104
125
 
105
126
  router.route('/api/integrations').get(
106
127
  catchAsyncError(async (req, res) => {
@@ -404,8 +425,9 @@ function setIntegrationRoutes(router, factory, getUserFromBearerToken) {
404
425
  * @param {Object} factory - Factory object containing moduleFactory
405
426
  * @param {import('../user/use-cases/get-user-from-bearer-token').GetUserFromBearerToken} getUserFromBearerToken - Use case for retrieving a user from a bearer token
406
427
  */
407
- function setEntityRoutes(router, factory, getUserFromBearerToken) {
428
+ function setEntityRoutes(router, factory, getUserFromBearerToken, useCases) {
408
429
  const { moduleFactory } = factory;
430
+ const { getCredentialForUser } = useCases;
409
431
  const getModuleInstance = async (userId, entityType) => {
410
432
  if (!moduleFactory.checkIsValidType(entityType)) {
411
433
  throw Boom.badRequest(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.396.607ab7a.0",
4
+ "version": "2.0.0--canary.396.d50d765.0",
5
5
  "dependencies": {
6
6
  "@hapi/boom": "^10.0.1",
7
7
  "aws-sdk": "^2.1200.0",
@@ -22,9 +22,9 @@
22
22
  "uuid": "^9.0.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@friggframework/eslint-config": "2.0.0--canary.396.607ab7a.0",
26
- "@friggframework/prettier-config": "2.0.0--canary.396.607ab7a.0",
27
- "@friggframework/test": "2.0.0--canary.396.607ab7a.0",
25
+ "@friggframework/eslint-config": "2.0.0--canary.396.d50d765.0",
26
+ "@friggframework/prettier-config": "2.0.0--canary.396.d50d765.0",
27
+ "@friggframework/test": "2.0.0--canary.396.d50d765.0",
28
28
  "@types/lodash": "4.17.15",
29
29
  "@typescript-eslint/eslint-plugin": "^8.0.0",
30
30
  "chai": "^4.3.6",
@@ -53,5 +53,5 @@
53
53
  },
54
54
  "homepage": "https://github.com/friggframework/frigg#readme",
55
55
  "description": "",
56
- "gitHead": "607ab7a7440562858c6d7440b8983a00931be283"
56
+ "gitHead": "d50d765cf88cd18a604ded97837926ad2ab0bc87"
57
57
  }