@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.
- 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 +44 -42
- 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 +46 -142
- package/integrations/integration-factory.js +251 -0
- package/integrations/integration-router.js +181 -303
- 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}/entity.js +0 -1
- 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 -56
- 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 -80
- 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 -71
- package/integrations/use-cases/delete-integration-for-user.js +0 -72
- package/integrations/use-cases/get-integration-for-user.js +0 -78
- package/integrations/use-cases/get-integration-instance-by-definition.js +0 -67
- package/integrations/use-cases/get-integration-instance.js +0 -82
- package/integrations/use-cases/get-integrations-for-user.js +0 -76
- 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 -91
- 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 -218
- 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 -108
- 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}/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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const { loadInstalledModules, Delegate } = require('../core');
|
|
2
|
+
|
|
3
|
+
const { Entity } = require('./entity');
|
|
4
|
+
const { ModuleManager } = require('./manager');
|
|
5
|
+
|
|
6
|
+
class EntityManager {
|
|
7
|
+
static primaryEntityClass = null; //primaryEntity;
|
|
8
|
+
|
|
9
|
+
static entityManagerClasses = loadInstalledModules().map(
|
|
10
|
+
(m) => m.EntityManager
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
static entityTypes = EntityManager.entityManagerClasses.map(
|
|
14
|
+
(ManagerClass) => ManagerClass.getName()
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
static async getEntitiesForUser(userId) {
|
|
18
|
+
const results = [];
|
|
19
|
+
for (const Manager of this.entityManagerClasses) {
|
|
20
|
+
results.push(...(await Manager.getEntitiesForUserId(userId)));
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static checkIsValidType(entityType) {
|
|
26
|
+
const indexOfEntity = EntityManager.entityTypes.indexOf(entityType);
|
|
27
|
+
return indexOfEntity >= 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static getEntityManagerClass(entityType = '') {
|
|
31
|
+
const normalizedType = entityType.toLowerCase();
|
|
32
|
+
|
|
33
|
+
const indexOfEntityType =
|
|
34
|
+
EntityManager.entityTypes.indexOf(normalizedType);
|
|
35
|
+
if (!EntityManager.checkIsValidType(normalizedType)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Error: Invalid entity type of ${normalizedType}, options are ${EntityManager.entityTypes.join(
|
|
38
|
+
', '
|
|
39
|
+
)}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const managerClass =
|
|
44
|
+
EntityManager.entityManagerClasses[indexOfEntityType];
|
|
45
|
+
|
|
46
|
+
if (!(managerClass.prototype instanceof ModuleManager)) {
|
|
47
|
+
throw new Error('The Entity is not an instance of ModuleManager');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return managerClass;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static async getEntityManagerInstanceFromEntityId(entityId, userId) {
|
|
54
|
+
const entityMO = new Entity();
|
|
55
|
+
const entity = await entityMO.get(entityId);
|
|
56
|
+
let entityManagerClass;
|
|
57
|
+
for (const Manager of this.entityManagerClasses) {
|
|
58
|
+
if (entity instanceof Manager.Entity.Model) {
|
|
59
|
+
entityManagerClass = Manager;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const instance = await entityManagerClass.getInstance({
|
|
63
|
+
userId,
|
|
64
|
+
entityId,
|
|
65
|
+
});
|
|
66
|
+
return instance;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { EntityManager };
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
const { Credential } = require('./credential');
|
|
2
|
+
const { EntityManager } = require('./entity-manager');
|
|
2
3
|
const { Entity } = require('./entity');
|
|
4
|
+
const { ModuleManager } = require('./manager');
|
|
3
5
|
const { ApiKeyRequester } = require('./requester/api-key');
|
|
4
6
|
const { BasicAuthRequester } = require('./requester/basic');
|
|
5
7
|
const { OAuth2Requester } = require('./requester/oauth-2');
|
|
6
8
|
const { Requester } = require('./requester/requester');
|
|
7
9
|
const { ModuleConstants } = require('./ModuleConstants');
|
|
10
|
+
const { ModuleFactory } = require('./module-factory');
|
|
11
|
+
const { Auther } = require('./auther');
|
|
8
12
|
|
|
9
13
|
module.exports = {
|
|
10
14
|
Credential,
|
|
15
|
+
EntityManager,
|
|
11
16
|
Entity,
|
|
17
|
+
ModuleManager,
|
|
12
18
|
ApiKeyRequester,
|
|
13
19
|
BasicAuthRequester,
|
|
14
20
|
OAuth2Requester,
|
|
15
21
|
Requester,
|
|
16
22
|
ModuleConstants,
|
|
23
|
+
ModuleFactory,
|
|
24
|
+
Auther
|
|
17
25
|
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const { Delegate } = require('../core');
|
|
2
|
+
const { Credential } = require('./credential');
|
|
3
|
+
const { Entity } = require('./entity');
|
|
4
|
+
const { get } = require('../assertions');
|
|
5
|
+
|
|
6
|
+
class ModuleManager extends Delegate {
|
|
7
|
+
static Entity = Entity;
|
|
8
|
+
static Credential = Credential;
|
|
9
|
+
|
|
10
|
+
constructor(params) {
|
|
11
|
+
super(params);
|
|
12
|
+
this.userId = get(params, 'userId', null); // Making this non-required
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static getName() {
|
|
16
|
+
throw new Error('Module name is not defined');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static async getInstance(params) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'getInstance is not implemented. It is required for ModuleManager. '
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static async getEntitiesForUserId(userId) {
|
|
26
|
+
// Only return non-internal fields. Leverages "select" and "options" to non-excepted fields and a pure object.
|
|
27
|
+
const list = await this.Entity.find(
|
|
28
|
+
{ user: userId },
|
|
29
|
+
'-dateCreated -dateUpdated -user -credentials -credential -__t -__v',
|
|
30
|
+
{ lean: true }
|
|
31
|
+
);
|
|
32
|
+
return list.map((entity) => ({
|
|
33
|
+
id: entity._id,
|
|
34
|
+
type: this.getName(),
|
|
35
|
+
...entity,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getEntityId() {
|
|
40
|
+
const list = await Entity.find({ user: this.userId });
|
|
41
|
+
if (list.length > 1) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
'There should not be more than one entity associated with a user for this specific class type'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (list.length == 0) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return list[0].id;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async validateAuthorizationRequirements() {
|
|
53
|
+
const requirements = await this.getAuthorizationRequirements();
|
|
54
|
+
let valid = true;
|
|
55
|
+
if (['oauth1', 'oauth2'].includes(requirements.type) && !requirements.url) {
|
|
56
|
+
valid = false;
|
|
57
|
+
}
|
|
58
|
+
return valid;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getAuthorizationRequirements(params) {
|
|
62
|
+
// this function must return a dictionary with the following format
|
|
63
|
+
// node only url key is required. Data would be used for Base Authentication
|
|
64
|
+
// let returnData = {
|
|
65
|
+
// url: "callback url for the data or teh redirect url for login",
|
|
66
|
+
// type: one of the types defined in modules/Constants.js
|
|
67
|
+
// data: ["required", "fields", "we", "may", "need"]
|
|
68
|
+
// }
|
|
69
|
+
throw new Error(
|
|
70
|
+
'Authorization requirements method getAuthorizationRequirements() is not defined in the class'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async testAuth(params) {
|
|
75
|
+
// this function must invoke a method on the API using authentication
|
|
76
|
+
// if it fails, an exception should be thrown
|
|
77
|
+
throw new Error(
|
|
78
|
+
'Authentication test method testAuth() is not defined in the class'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async processAuthorizationCallback(params) {
|
|
83
|
+
// this function takes in a dictionary of callback information along with
|
|
84
|
+
// a unique user id to associate with the entity in the form of
|
|
85
|
+
// {
|
|
86
|
+
// userId: "some id",
|
|
87
|
+
// data: {}
|
|
88
|
+
// }
|
|
89
|
+
|
|
90
|
+
throw new Error(
|
|
91
|
+
'Authorization requirements method processAuthorizationCallback() is not defined in the class'
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//----------------------------------------------------------------------------------------------------
|
|
96
|
+
// optional
|
|
97
|
+
|
|
98
|
+
async getEntityOptions() {
|
|
99
|
+
// May not be needed if the callback already creates the entity, such as in situations
|
|
100
|
+
// like HubSpot where the account is determined in the authorization flow.
|
|
101
|
+
// This should only be used in situations such as FreshBooks where the user needs to make
|
|
102
|
+
// an account decision on the front end.
|
|
103
|
+
throw new Error(
|
|
104
|
+
'Entity requirement method getEntityOptions() is not defined in the class'
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async findOrCreateEntity(params) {
|
|
109
|
+
// May not be needed if the callback already creates the entity, such as in situations
|
|
110
|
+
// like HubSpot where the account is determined in the authorization flow.
|
|
111
|
+
// This should only be used in situations such as FreshBooks where the user needs to make
|
|
112
|
+
// an account decision on the front end.
|
|
113
|
+
throw new Error(
|
|
114
|
+
'Entity requirement method findOrCreateEntity() is not defined in the class'
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async getAllSyncObjects(SyncClass) {
|
|
119
|
+
// takes in a Sync class and will return all objects associated with the SyncClass in an array
|
|
120
|
+
// in the form of
|
|
121
|
+
// [
|
|
122
|
+
// {...object1},{...object2}...
|
|
123
|
+
// ]
|
|
124
|
+
|
|
125
|
+
throw new Error(
|
|
126
|
+
'The method "getAllSyncObjects()" is not defined in the class'
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async batchCreateSyncObjects(syncObjects, syncManager) {
|
|
131
|
+
// takes in an array of Sync objects that has two pieces of data that
|
|
132
|
+
// are important to the updating module:
|
|
133
|
+
// 1. obj.data -> The data mapped to the obj.keys data
|
|
134
|
+
// 2. obj.syncId -> the id of the newly created sync object in our database. You will need to update
|
|
135
|
+
// the sync object in the database with the your id associated with this data. You
|
|
136
|
+
// can do this by calling the SyncManager function updateSyncObject.
|
|
137
|
+
// [
|
|
138
|
+
// syncObject1,syncObject2, ...
|
|
139
|
+
// ]
|
|
140
|
+
|
|
141
|
+
throw new Error(
|
|
142
|
+
'The method "batchUpdateSyncObjects()" is not defined in the class'
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async batchUpdateSyncObjects(syncObjects, syncManager) {
|
|
147
|
+
// takes in an array of Sync objects that has two pieces of data that
|
|
148
|
+
// are important to the updating module:
|
|
149
|
+
// 1. obj.data -> The data mapped to the obj.keys data
|
|
150
|
+
// 2. obj.moduleObjectIds[this.constructor.getName()] -> Indexed from the point of view of the module manager
|
|
151
|
+
// it will return a json object holding all of the keys
|
|
152
|
+
// required update this datapoint. an example would be:
|
|
153
|
+
// {companyId:12, email:"test@test.com"}
|
|
154
|
+
// [
|
|
155
|
+
// syncObject1,syncObject2, ...
|
|
156
|
+
// ]
|
|
157
|
+
|
|
158
|
+
throw new Error(
|
|
159
|
+
'The method "batchUpdateSyncObjects()" is not defined in the class'
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async markCredentialsInvalid() {
|
|
164
|
+
this.credential.auth_is_valid = false;
|
|
165
|
+
return await this.credential.save();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = { ModuleManager };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const { Entity } = require('./entity');
|
|
2
|
+
const { Auther } = require('./auther');
|
|
3
|
+
|
|
4
|
+
class ModuleFactory {
|
|
5
|
+
constructor(...params) {
|
|
6
|
+
this.moduleDefinitions = params;
|
|
7
|
+
this.moduleTypes = this.moduleDefinitions.map((def) => def.moduleName);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async getEntitiesForUser(userId) {
|
|
11
|
+
let results = [];
|
|
12
|
+
for (const moduleDefinition of this.moduleDefinitions) {
|
|
13
|
+
const moduleInstance = await Auther.getInstance({
|
|
14
|
+
userId,
|
|
15
|
+
definition: moduleDefinition,
|
|
16
|
+
});
|
|
17
|
+
const list = await moduleInstance.getEntitiesForUserId(userId);
|
|
18
|
+
results.push(...list);
|
|
19
|
+
}
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
checkIsValidType(entityType) {
|
|
24
|
+
return this.moduleTypes.includes(entityType);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getModuleDefinitionFromTypeName(typeName) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async getModuleInstanceFromEntityId(entityId, userId) {
|
|
32
|
+
const entity = await Entity.findById(entityId);
|
|
33
|
+
const moduleDefinition = this.moduleDefinitions.find(
|
|
34
|
+
(def) =>
|
|
35
|
+
entity.toJSON()['__t'] ===
|
|
36
|
+
Auther.getEntityModelFromDefinition(def).modelName
|
|
37
|
+
);
|
|
38
|
+
if (!moduleDefinition) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
'Module definition not found for entity type: ' + entity['__t']
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return await Auther.getInstance({
|
|
44
|
+
userId,
|
|
45
|
+
entityId,
|
|
46
|
+
definition: moduleDefinition,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async getInstanceFromTypeName(typeName, userId) {
|
|
51
|
+
const moduleDefinition = this.moduleDefinitions.find(
|
|
52
|
+
(def) => def.getName() === typeName
|
|
53
|
+
);
|
|
54
|
+
return await Auther.getInstance({
|
|
55
|
+
userId,
|
|
56
|
+
definition: moduleDefinition,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { ModuleFactory };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { get } = require('
|
|
2
|
-
const { OAuth2Requester } = require('
|
|
1
|
+
const { get } = require('../../assertions');
|
|
2
|
+
const { OAuth2Requester } = require('../../module-plugin');
|
|
3
3
|
|
|
4
4
|
class Api extends OAuth2Requester {
|
|
5
5
|
constructor(params) {
|
|
@@ -23,12 +23,7 @@ class Api extends OAuth2Requester {
|
|
|
23
23
|
return this.authorizationUri;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
url: this.getAuthUri(),
|
|
29
|
-
type: 'oauth2',
|
|
30
|
-
};
|
|
31
|
-
}
|
|
26
|
+
|
|
32
27
|
}
|
|
33
28
|
|
|
34
29
|
module.exports = { Api };
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
require('dotenv').config();
|
|
2
|
-
const {
|
|
3
|
-
const {
|
|
4
|
-
const config = {
|
|
2
|
+
const {Api} = require('./api');
|
|
3
|
+
const {get} = require('../../assertions');
|
|
4
|
+
const config = {name: 'anapi'}
|
|
5
5
|
|
|
6
6
|
const Definition = {
|
|
7
7
|
API: Api,
|
|
8
|
-
|
|
9
|
-
url: 'http://localhost:3000/redirect/anapi',
|
|
10
|
-
type: 'oauth2',
|
|
11
|
-
}),
|
|
12
|
-
getName: function () { return config.name },
|
|
8
|
+
getName: function() {return config.name},
|
|
13
9
|
moduleName: config.name,
|
|
14
10
|
modelName: 'AnApi',
|
|
15
11
|
requiredAuthMethods: {
|
|
16
|
-
getToken: async function
|
|
12
|
+
getToken: async function(api, params){
|
|
17
13
|
const code = get(params.data, 'code');
|
|
18
14
|
return api.getTokenFromCode(code);
|
|
19
15
|
},
|
|
20
|
-
getEntityDetails: async function
|
|
16
|
+
getEntityDetails: async function(api, callbackParams, tokenResponse, userId) {
|
|
21
17
|
const userDetails = await api.getUserDetails();
|
|
22
18
|
return {
|
|
23
19
|
identifiers: { externalId: userDetails.portalId, user: userId },
|
|
@@ -30,14 +26,14 @@ const Definition = {
|
|
|
30
26
|
],
|
|
31
27
|
entity: [],
|
|
32
28
|
},
|
|
33
|
-
getCredentialDetails: async function
|
|
29
|
+
getCredentialDetails: async function(api, userId) {
|
|
34
30
|
const userDetails = await api.getUserDetails();
|
|
35
31
|
return {
|
|
36
32
|
identifiers: { externalId: userDetails.portalId, user: userId },
|
|
37
33
|
details: {}
|
|
38
34
|
};
|
|
39
35
|
},
|
|
40
|
-
testAuthRequest: async function
|
|
36
|
+
testAuthRequest: async function(api){
|
|
41
37
|
return api.getUserDetails()
|
|
42
38
|
},
|
|
43
39
|
},
|
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.
|
|
4
|
+
"version": "2.0.0--canary.398.24926ac.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.
|
|
26
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
27
|
-
"@friggframework/test": "2.0.0--canary.
|
|
25
|
+
"@friggframework/eslint-config": "2.0.0--canary.398.24926ac.0",
|
|
26
|
+
"@friggframework/prettier-config": "2.0.0--canary.398.24926ac.0",
|
|
27
|
+
"@friggframework/test": "2.0.0--canary.398.24926ac.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": "
|
|
56
|
+
"gitHead": "24926ace5bdfefc9187ad658f26a3c67d6f8ec96"
|
|
57
57
|
}
|
package/syncs/sync.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare module "@friggframework/integrations" {
|
|
2
2
|
import { Delegate, IFriggDelegate } from "@friggframework/core";
|
|
3
3
|
import { Model } from "mongoose";
|
|
4
|
+
import { EntityManager } from "@friggframework/module-plugin";
|
|
4
5
|
|
|
5
6
|
export class Integration extends Model {
|
|
6
7
|
entities: any[];
|
|
@@ -18,7 +19,8 @@ declare module "@friggframework/integrations" {
|
|
|
18
19
|
|
|
19
20
|
export class IntegrationManager
|
|
20
21
|
extends Delegate
|
|
21
|
-
implements IFriggIntegrationManager
|
|
22
|
+
implements IFriggIntegrationManager
|
|
23
|
+
{
|
|
22
24
|
integration: Integration;
|
|
23
25
|
primaryInstance: any;
|
|
24
26
|
targetInstance: any;
|
|
@@ -54,6 +56,7 @@ declare module "@friggframework/integrations" {
|
|
|
54
56
|
entities: { id: string; user: any },
|
|
55
57
|
userId: string,
|
|
56
58
|
config: any,
|
|
59
|
+
EntityManager: EntityManager
|
|
57
60
|
): Promise<any>;
|
|
58
61
|
|
|
59
62
|
static getFormattedIntegration(
|
|
@@ -113,7 +116,8 @@ declare module "@friggframework/integrations" {
|
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
export class IntegrationConfigManager
|
|
116
|
-
implements IFriggIntegrationConfigManager
|
|
119
|
+
implements IFriggIntegrationConfigManager
|
|
120
|
+
{
|
|
117
121
|
options: IntegrationOptions[];
|
|
118
122
|
primary: any;
|
|
119
123
|
|
|
@@ -9,7 +9,21 @@ declare module "@friggframework/module-plugin" {
|
|
|
9
9
|
externalId: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
export class EntityManager implements IFriggEntityManager {
|
|
13
|
+
static primaryEntityClass: any;
|
|
14
|
+
static entityManagerClasses: any[];
|
|
15
|
+
static entityTypes: string[];
|
|
16
|
+
static getEntitiesForUser(userId: string): Promise<any[]>;
|
|
17
|
+
static checkIsValidType(entityType: string): boolean;
|
|
18
|
+
static getEntityManagerClass(entityType?: string): any;
|
|
19
|
+
|
|
20
|
+
static getEntityManagerInstanceFromEntityId(
|
|
21
|
+
entityId: string,
|
|
22
|
+
userId: string
|
|
23
|
+
): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface IFriggEntityManager {}
|
|
13
27
|
|
|
14
28
|
export class Entity extends Model {
|
|
15
29
|
credentialId: string;
|
|
@@ -20,7 +34,42 @@ declare module "@friggframework/module-plugin" {
|
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
export type MappedEntity = Entity & { id: string; type: any };
|
|
37
|
+
export class ModuleManager extends Delegate implements IFriggModuleManager {
|
|
38
|
+
static Entity: Entity;
|
|
39
|
+
static Credential: Credential;
|
|
40
|
+
|
|
41
|
+
constructor(params: { userId: string });
|
|
23
42
|
|
|
43
|
+
static getName(): any;
|
|
44
|
+
static getInstance(params: any): Promise<any>;
|
|
45
|
+
static getEntitiesForUserId(userId: string): Promise<MappedEntity[]>;
|
|
46
|
+
|
|
47
|
+
batchCreateSyncObjects(syncObjects: any, syncManager: any): Promise<any>;
|
|
48
|
+
batchUpdateSyncObjects(syncObjects: any, syncManager: any): Promise<any>;
|
|
49
|
+
findOrCreateEntity(params: any): Promise<any>;
|
|
50
|
+
getAllSyncObjects(SyncClass: any): Promise<any>;
|
|
51
|
+
getAuthorizationRequirements(params: any): Promise<any>;
|
|
52
|
+
getEntityId(): Promise<string>;
|
|
53
|
+
getEntityOptions(): Promise<any>;
|
|
54
|
+
markCredentialsInvalid(): Promise<Credential>;
|
|
55
|
+
processAuthorizationCallback(params: any): Promise<any>;
|
|
56
|
+
testAuth(params: any): Promise<any>;
|
|
57
|
+
validateAuthorizationRequirements(): Promise<boolean>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface IFriggModuleManager extends IFriggDelegate {
|
|
61
|
+
getEntityId(): Promise<string>;
|
|
62
|
+
validateAuthorizationRequirements(): Promise<boolean>;
|
|
63
|
+
getAuthorizationRequirements(params: any): Promise<any>;
|
|
64
|
+
testAuth(params: any): Promise<any>;
|
|
65
|
+
processAuthorizationCallback(params: any): Promise<any>;
|
|
66
|
+
getEntityOptions(): Promise<any>;
|
|
67
|
+
findOrCreateEntity(params: any): Promise<any>;
|
|
68
|
+
getAllSyncObjects(SyncClass: any): Promise<any>;
|
|
69
|
+
batchCreateSyncObjects(syncObjects: any, syncManager: any): Promise<any>;
|
|
70
|
+
batchUpdateSyncObjects(syncObjects: any, syncManager: any): Promise<any>;
|
|
71
|
+
markCredentialsInvalid(): Promise<Credential>;
|
|
72
|
+
}
|
|
24
73
|
|
|
25
74
|
export class Requester implements IFriggRequester {
|
|
26
75
|
DLGT_INVALID_AUTH: string;
|
|
@@ -89,7 +138,8 @@ declare module "@friggframework/module-plugin" {
|
|
|
89
138
|
|
|
90
139
|
export class ApiKeyRequester
|
|
91
140
|
extends Requester
|
|
92
|
-
implements IFriggApiKeyRequester
|
|
141
|
+
implements IFriggApiKeyRequester
|
|
142
|
+
{
|
|
93
143
|
API_KEY_NAME: string;
|
|
94
144
|
API_KEY_VALUE: any;
|
|
95
145
|
|
|
@@ -110,7 +160,8 @@ declare module "@friggframework/module-plugin" {
|
|
|
110
160
|
|
|
111
161
|
export class BasicAuthRequester
|
|
112
162
|
extends Requester
|
|
113
|
-
implements IFriggBasicAuthRequester
|
|
163
|
+
implements IFriggBasicAuthRequester
|
|
164
|
+
{
|
|
114
165
|
password: string;
|
|
115
166
|
username: string;
|
|
116
167
|
|
|
@@ -138,7 +189,8 @@ declare module "@friggframework/module-plugin" {
|
|
|
138
189
|
|
|
139
190
|
export class OAuth2Requester
|
|
140
191
|
extends Requester
|
|
141
|
-
implements IFriggOAuth2Requester
|
|
192
|
+
implements IFriggOAuth2Requester
|
|
193
|
+
{
|
|
142
194
|
DLGT_TOKEN_DEAUTHORIZED: string;
|
|
143
195
|
DLGT_TOKEN_UPDATE: string;
|
|
144
196
|
accessTokenExpire: any;
|
package/types/syncs/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ declare module "@friggframework/syncs/manager" {
|
|
|
28
28
|
confirmCreate(
|
|
29
29
|
syncObj: Sync,
|
|
30
30
|
createdId: string,
|
|
31
|
+
moduleManager: any
|
|
31
32
|
): Promise<any>;
|
|
32
33
|
confirmUpdate(syncObj: Sync): Promise<any>;
|
|
33
34
|
createSyncDBObject(objArr: any[], entities: any[]): Promise<any>;
|
|
@@ -49,6 +50,7 @@ declare module "@friggframework/syncs/manager" {
|
|
|
49
50
|
confirmCreate(
|
|
50
51
|
syncObj: Sync,
|
|
51
52
|
createdId: string,
|
|
53
|
+
moduleManager: any
|
|
52
54
|
): Promise<any>;
|
|
53
55
|
confirmUpdate(syncObj: Sync): Promise<any>;
|
|
54
56
|
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const { Credential } = require('../modules');
|
|
2
|
-
|
|
3
|
-
class CredentialRepository {
|
|
4
|
-
async findCredentialById(id) {
|
|
5
|
-
return Credential.findById(id);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
async updateAuthenticationStatus(credentialId, authIsValid) {
|
|
9
|
-
return Credential.updateOne({ _id: credentialId }, { $set: { auth_is_valid: authIsValid } });
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Permanently remove a credential document.
|
|
14
|
-
* @param {string} credentialId
|
|
15
|
-
* @returns {Promise<import('mongoose').DeleteResult>}
|
|
16
|
-
*/
|
|
17
|
-
async deleteCredentialById(credentialId) {
|
|
18
|
-
return Credential.deleteOne({ _id: credentialId });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Create a new credential or update an existing one matching the identifiers.
|
|
23
|
-
* `credentialDetails` format: { identifiers: { ... }, details: { ... } }
|
|
24
|
-
* Identifiers are used in the query filter; details are merged into the document.
|
|
25
|
-
* @param {{identifiers: Object, details: Object}} credentialDetails
|
|
26
|
-
* @returns {Promise<Object>} The persisted credential (lean object)
|
|
27
|
-
*/
|
|
28
|
-
async upsertCredential(credentialDetails) {
|
|
29
|
-
const { identifiers, details } = credentialDetails;
|
|
30
|
-
if (!identifiers) throw new Error('identifiers required to upsert credential');
|
|
31
|
-
|
|
32
|
-
const query = { ...identifiers };
|
|
33
|
-
|
|
34
|
-
const update = { $set: { ...details } };
|
|
35
|
-
|
|
36
|
-
const options = {
|
|
37
|
-
upsert: true,
|
|
38
|
-
new: true,
|
|
39
|
-
setDefaultsOnInsert: true,
|
|
40
|
-
lean: true,
|
|
41
|
-
strict: false,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const credential = await Credential.findOneAndUpdate(query, update, options);
|
|
45
|
-
return {
|
|
46
|
-
id: credential._id.toString(),
|
|
47
|
-
externalId: credential.externalId,
|
|
48
|
-
userId: credential.user.toString(),
|
|
49
|
-
auth_is_valid: credential.auth_is_valid,
|
|
50
|
-
access_token: credential.access_token,
|
|
51
|
-
refresh_token: credential.refresh_token,
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = { CredentialRepository };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
class GetCredentialForUser {
|
|
2
|
-
constructor({ credentialRepository }) {
|
|
3
|
-
this.credentialRepository = credentialRepository;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
async execute(credentialId, userId) {
|
|
7
|
-
const credential = await this.credentialRepository.findCredentialById(credentialId);
|
|
8
|
-
|
|
9
|
-
if (!credential) {
|
|
10
|
-
throw new Error(`Credential with id ${credentialId} not found`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (credential.user.toString() !== userId.toString()) {
|
|
14
|
-
throw new Error(`Credential ${credentialId} does not belong to user ${userId}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return credential;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = { GetCredentialForUser };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
class UpdateAuthenticationStatus {
|
|
2
|
-
constructor({ credentialRepository }) {
|
|
3
|
-
this.credentialRepository = credentialRepository;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {string} credentialId
|
|
8
|
-
* @param {boolean} authIsValid
|
|
9
|
-
*/
|
|
10
|
-
async execute(credentialId, authIsValid) {
|
|
11
|
-
await this.credentialRepository.updateAuthenticationStatus(credentialId, authIsValid);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = { UpdateAuthenticationStatus };
|