@friggframework/core 2.0.0--canary.405.b81908d.0 → 2.0.0--canary.397.c07f148.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 +931 -50
- package/core/create-handler.js +1 -0
- package/credential/credential-repository.js +56 -0
- package/credential/use-cases/get-credential-for-user.js +21 -0
- package/credential/use-cases/update-authentication-status.js +15 -0
- package/encrypt/encrypt.js +27 -4
- package/handlers/app-definition-loader.js +38 -0
- package/handlers/app-handler-helpers.js +0 -3
- package/handlers/backend-utils.js +42 -44
- package/handlers/routers/auth.js +3 -14
- package/handlers/routers/integration-defined-routers.js +8 -5
- package/handlers/routers/user.js +25 -5
- package/handlers/workers/integration-defined-workers.js +6 -3
- package/index.js +1 -16
- package/integrations/index.js +0 -5
- package/integrations/integration-base.js +142 -46
- package/integrations/integration-repository.js +80 -0
- package/integrations/integration-router.js +303 -181
- package/integrations/options.js +1 -1
- package/integrations/tests/doubles/dummy-integration-class.js +90 -0
- package/integrations/tests/doubles/test-integration-repository.js +89 -0
- package/integrations/tests/use-cases/create-integration.test.js +124 -0
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +143 -0
- package/integrations/tests/use-cases/get-integration-for-user.test.js +143 -0
- package/integrations/tests/use-cases/get-integration-instance.test.js +169 -0
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +169 -0
- package/integrations/tests/use-cases/get-possible-integrations.test.js +188 -0
- package/integrations/tests/use-cases/update-integration-messages.test.js +142 -0
- package/integrations/tests/use-cases/update-integration-status.test.js +103 -0
- package/integrations/tests/use-cases/update-integration.test.js +134 -0
- package/integrations/use-cases/create-integration.js +71 -0
- package/integrations/use-cases/delete-integration-for-user.js +72 -0
- package/integrations/use-cases/get-integration-for-user.js +78 -0
- package/integrations/use-cases/get-integration-instance-by-definition.js +67 -0
- package/integrations/use-cases/get-integration-instance.js +82 -0
- package/integrations/use-cases/get-integrations-for-user.js +76 -0
- package/integrations/use-cases/get-possible-integrations.js +27 -0
- package/integrations/use-cases/index.js +11 -0
- package/integrations/use-cases/update-integration-messages.js +31 -0
- package/integrations/use-cases/update-integration-status.js +28 -0
- package/integrations/use-cases/update-integration.js +91 -0
- package/integrations/utils/map-integration-dto.js +36 -0
- package/{module-plugin → modules}/entity.js +1 -0
- package/{module-plugin → modules}/index.js +0 -8
- package/modules/module-factory.js +54 -0
- package/modules/module-repository.js +107 -0
- package/modules/module.js +218 -0
- package/{module-plugin → modules}/test/mock-api/api.js +8 -3
- package/{module-plugin → modules}/test/mock-api/definition.js +12 -8
- package/modules/tests/doubles/test-module-factory.js +16 -0
- package/modules/tests/doubles/test-module-repository.js +19 -0
- package/modules/use-cases/get-entities-for-user.js +32 -0
- package/modules/use-cases/get-entity-options-by-id.js +58 -0
- package/modules/use-cases/get-entity-options-by-type.js +34 -0
- package/modules/use-cases/get-module-instance-from-type.js +31 -0
- package/modules/use-cases/get-module.js +56 -0
- package/modules/use-cases/process-authorization-callback.js +108 -0
- package/modules/use-cases/refresh-entity-options.js +58 -0
- package/modules/use-cases/test-module-auth.js +54 -0
- package/modules/utils/map-module-dto.js +18 -0
- package/package.json +5 -5
- package/syncs/sync.js +0 -1
- package/types/integrations/index.d.ts +2 -6
- package/types/module-plugin/index.d.ts +4 -56
- package/types/syncs/index.d.ts +0 -2
- package/user/tests/doubles/test-user-repository.js +72 -0
- package/user/tests/use-cases/create-individual-user.test.js +24 -0
- package/user/tests/use-cases/create-organization-user.test.js +28 -0
- package/user/tests/use-cases/create-token-for-user-id.test.js +19 -0
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +64 -0
- package/user/tests/use-cases/login-user.test.js +140 -0
- package/user/use-cases/create-individual-user.js +61 -0
- package/user/use-cases/create-organization-user.js +47 -0
- package/user/use-cases/create-token-for-user-id.js +30 -0
- package/user/use-cases/get-user-from-bearer-token.js +77 -0
- package/user/use-cases/login-user.js +122 -0
- package/user/user-repository.js +62 -0
- package/user/user.js +77 -0
- package/handlers/routers/HEALTHCHECK.md +0 -240
- package/handlers/routers/health.js +0 -451
- package/handlers/routers/health.test.js +0 -203
- package/handlers/routers/middleware/loadUser.js +0 -15
- package/handlers/routers/middleware/requireLoggedInUser.js +0 -12
- package/integrations/create-frigg-backend.js +0 -31
- package/integrations/integration-factory.js +0 -251
- package/integrations/integration-user.js +0 -144
- package/integrations/test/integration-base.test.js +0 -144
- package/module-plugin/auther.js +0 -393
- package/module-plugin/entity-manager.js +0 -70
- package/module-plugin/manager.js +0 -169
- package/module-plugin/module-factory.js +0 -61
- /package/{module-plugin → modules}/ModuleConstants.js +0 -0
- /package/{module-plugin → modules}/credential.js +0 -0
- /package/{module-plugin → modules}/requester/api-key.js +0 -0
- /package/{module-plugin → modules}/requester/basic.js +0 -0
- /package/{module-plugin → modules}/requester/oauth-2.js +0 -0
- /package/{module-plugin → modules}/requester/requester.js +0 -0
- /package/{module-plugin → modules}/requester/requester.test.js +0 -0
- /package/{module-plugin → modules}/test/auther.test.js +0 -0
- /package/{module-plugin → modules}/test/mock-api/mocks/hubspot.js +0 -0
package/module-plugin/manager.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
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 };
|
|
@@ -1,61 +0,0 @@
|
|
|
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 };
|
|
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
|