@friggframework/core 2.0.0--canary.397.4cedf64.0 → 2.0.0--canary.397.6ecf8f5.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/integrations/integration-base.js +32 -22
- package/integrations/integration-repository.js +13 -0
- package/integrations/integration.js +4 -0
- package/integrations/use-cases/create-integration.js +1 -1
- package/integrations/use-cases/update-integration-messages.js +20 -0
- package/integrations/use-cases/update-integration-status.js +12 -0
- package/package.json +5 -5
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const { IntegrationMapping } = require('./integration-mapping');
|
|
2
2
|
const { Options } = require('./options');
|
|
3
|
+
const { UpdateIntegrationStatus } = require('./use-cases/update-integration-status');
|
|
4
|
+
const { IntegrationRepository } = require('./integration-repository');
|
|
5
|
+
const { UpdateIntegrationMessages } = require('./use-cases/update-integration-messages');
|
|
3
6
|
|
|
4
7
|
const constantsToBeMigrated = {
|
|
5
8
|
defaultEvents: {
|
|
@@ -21,6 +24,11 @@ const constantsToBeMigrated = {
|
|
|
21
24
|
|
|
22
25
|
class IntegrationBase {
|
|
23
26
|
|
|
27
|
+
// todo: maybe we can pass this as Dependency Injection in the sub-class constructor
|
|
28
|
+
integrationRepository = new IntegrationRepository();
|
|
29
|
+
updateIntegrationStatus = new UpdateIntegrationStatus({ integrationRepository: this.integrationRepository });
|
|
30
|
+
updateIntegrationMessages = new UpdateIntegrationMessages({ integrationRepository: this.integrationRepository });
|
|
31
|
+
|
|
24
32
|
static getOptionDetails() {
|
|
25
33
|
const options = new Options({
|
|
26
34
|
module: Object.values(this.Definition.modules)[0], // This is a placeholder until we revamp the frontend
|
|
@@ -76,6 +84,7 @@ class IntegrationBase {
|
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
constructor(params) {
|
|
87
|
+
|
|
79
88
|
this.defaultEvents = {
|
|
80
89
|
[constantsToBeMigrated.defaultEvents.ON_CREATE]: {
|
|
81
90
|
type: constantsToBeMigrated.types.LIFE_CYCLE_EVENT,
|
|
@@ -124,7 +133,7 @@ class IntegrationBase {
|
|
|
124
133
|
|
|
125
134
|
async validateConfig() {
|
|
126
135
|
const configOptions = await this.getConfigOptions();
|
|
127
|
-
const currentConfig = this.
|
|
136
|
+
const currentConfig = this.getConfig();
|
|
128
137
|
let needsConfig = false;
|
|
129
138
|
for (const option of configOptions) {
|
|
130
139
|
if (option.required) {
|
|
@@ -136,17 +145,18 @@ class IntegrationBase {
|
|
|
136
145
|
)
|
|
137
146
|
) {
|
|
138
147
|
needsConfig = true;
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
await this.updateIntegrationMessages.execute(
|
|
149
|
+
this.id,
|
|
150
|
+
'warnings',
|
|
151
|
+
'Config Validation Error',
|
|
152
|
+
`Missing required field of ${option.label}`,
|
|
153
|
+
Date.now()
|
|
154
|
+
);
|
|
144
155
|
}
|
|
145
156
|
}
|
|
146
157
|
}
|
|
147
158
|
if (needsConfig) {
|
|
148
|
-
this.
|
|
149
|
-
await this.record.save();
|
|
159
|
+
await this.updateIntegrationStatus.execute(this.id, 'NEEDS_CONFIG');
|
|
150
160
|
}
|
|
151
161
|
}
|
|
152
162
|
|
|
@@ -158,34 +168,36 @@ class IntegrationBase {
|
|
|
158
168
|
await this[module].testAuth();
|
|
159
169
|
} catch {
|
|
160
170
|
didAuthPass = false;
|
|
161
|
-
this.
|
|
162
|
-
|
|
163
|
-
|
|
171
|
+
await this.updateIntegrationMessages.execute(
|
|
172
|
+
this.id,
|
|
173
|
+
'errors',
|
|
174
|
+
'Authentication Error',
|
|
175
|
+
`There was an error with your ${this[
|
|
164
176
|
module
|
|
165
177
|
].constructor.getName()} Entity.
|
|
166
178
|
Please reconnect/re-authenticate, or reach out to Support for assistance.`,
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
Date.now()
|
|
180
|
+
);
|
|
169
181
|
}
|
|
170
182
|
}
|
|
171
183
|
|
|
172
184
|
if (!didAuthPass) {
|
|
173
|
-
this.
|
|
174
|
-
this.record.markModified('messages.error');
|
|
175
|
-
await this.record.save();
|
|
185
|
+
await this.updateIntegrationStatus.execute(this.id, 'ERROR');
|
|
176
186
|
}
|
|
177
187
|
}
|
|
178
188
|
|
|
179
189
|
async getMapping(sourceId) {
|
|
180
|
-
|
|
190
|
+
// todo: this should be a use case
|
|
191
|
+
return IntegrationMapping.findBy(this.id, sourceId);
|
|
181
192
|
}
|
|
182
193
|
|
|
183
194
|
async upsertMapping(sourceId, mapping) {
|
|
184
195
|
if (!sourceId) {
|
|
185
196
|
throw new Error(`sourceId must be set`);
|
|
186
197
|
}
|
|
198
|
+
// todo: this should be a use case
|
|
187
199
|
return await IntegrationMapping.upsert(
|
|
188
|
-
this.
|
|
200
|
+
this.id,
|
|
189
201
|
sourceId,
|
|
190
202
|
mapping
|
|
191
203
|
);
|
|
@@ -194,10 +206,8 @@ class IntegrationBase {
|
|
|
194
206
|
/**
|
|
195
207
|
* CHILDREN CAN OVERRIDE THESE CONFIGURATION METHODS
|
|
196
208
|
*/
|
|
197
|
-
async onCreate(
|
|
198
|
-
this.
|
|
199
|
-
await this.record.save();
|
|
200
|
-
return this.record;
|
|
209
|
+
async onCreate({ integrationId }) {
|
|
210
|
+
await this.updateIntegrationStatus.execute(integrationId, 'ENABLED');
|
|
201
211
|
}
|
|
202
212
|
|
|
203
213
|
async onUpdate(params) { }
|
|
@@ -31,6 +31,19 @@ class IntegrationRepository {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
async updateIntegrationStatus(integrationId, status) {
|
|
35
|
+
const integrationRecord = await IntegrationModel.updateOne({ _id: integrationId }, { status });
|
|
36
|
+
return integrationRecord.acknowledged;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async updateIntegrationMessages(integrationId, messageType, messageTitle, messageBody, messageTimestamp) {
|
|
40
|
+
const integrationRecord = await IntegrationModel.updateOne(
|
|
41
|
+
{ _id: integrationId },
|
|
42
|
+
{ $push: { [`messages.${messageType}`]: { title: messageTitle, message: messageBody, timestamp: messageTimestamp } } }
|
|
43
|
+
);
|
|
44
|
+
return integrationRecord.acknowledged;
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
async createIntegration(entities, userId, config) {
|
|
35
48
|
const integrationRecord = await IntegrationModel.create({
|
|
36
49
|
entities: entities,
|
|
@@ -148,6 +148,10 @@ class Integration {
|
|
|
148
148
|
// Core methods that should always be on Integration entity
|
|
149
149
|
// These override any behavior methods with the same name
|
|
150
150
|
|
|
151
|
+
getConfig() {
|
|
152
|
+
return this.config;
|
|
153
|
+
}
|
|
154
|
+
|
|
151
155
|
// Module access helpers
|
|
152
156
|
getModule(key) {
|
|
153
157
|
return this.modules[key];
|
|
@@ -48,7 +48,7 @@ class CreateIntegration {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
await integrationInstance.initialize();
|
|
51
|
-
await integrationInstance.send('ON_CREATE', {});
|
|
51
|
+
await integrationInstance.send('ON_CREATE', { integrationId: integrationRecord.id });
|
|
52
52
|
|
|
53
53
|
return mapIntegrationClassToIntegrationDTO(integrationInstance);
|
|
54
54
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class UpdateIntegrationMessages {
|
|
2
|
+
constructor({ integrationRepository }) {
|
|
3
|
+
this.integrationRepository = integrationRepository;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} integrationId
|
|
8
|
+
* @param {string} messageType - 'errors', 'warnings', 'info' or 'logs'
|
|
9
|
+
* @param {string} messageTitle,
|
|
10
|
+
* @param {string} messageBody,
|
|
11
|
+
* @param {string} messageTimestamp,
|
|
12
|
+
* @returns {Promise<Object>}
|
|
13
|
+
*/
|
|
14
|
+
async execute(integrationId, messageType, messageTitle, messageBody, messageTimestamp) {
|
|
15
|
+
const integration = await this.integrationRepository.updateIntegrationMessages(integrationId, messageType, messageTitle, messageBody, messageTimestamp);
|
|
16
|
+
return integration;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { UpdateIntegrationMessages };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class UpdateIntegrationStatus {
|
|
2
|
+
constructor({ integrationRepository }) {
|
|
3
|
+
this.integrationRepository = integrationRepository;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async execute(integrationId, status) {
|
|
7
|
+
const integration = await this.integrationRepository.updateIntegrationStatus(integrationId, status);
|
|
8
|
+
return integration;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = { UpdateIntegrationStatus };
|
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.397.
|
|
4
|
+
"version": "2.0.0--canary.397.6ecf8f5.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.397.
|
|
26
|
-
"@friggframework/prettier-config": "2.0.0--canary.397.
|
|
27
|
-
"@friggframework/test": "2.0.0--canary.397.
|
|
25
|
+
"@friggframework/eslint-config": "2.0.0--canary.397.6ecf8f5.0",
|
|
26
|
+
"@friggframework/prettier-config": "2.0.0--canary.397.6ecf8f5.0",
|
|
27
|
+
"@friggframework/test": "2.0.0--canary.397.6ecf8f5.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": "6ecf8f59b4e8e90f6a83c19af86c437504e776d6"
|
|
57
57
|
}
|