@friggframework/core 1.2.2 → 1.3.0--canary.325.7243e56.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/CHANGELOG.md +0 -26
- package/core/create-handler.js +0 -10
- package/integrations/integration-base.js +10 -19
- package/module-plugin/module-factory.js +17 -18
- package/package.json +5 -5
- package/core/secrets-to-env.js +0 -61
package/CHANGELOG.md
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
# v1.2.2 (Fri Aug 09 2024)
|
|
2
|
-
|
|
3
|
-
#### 🐛 Bug Fix
|
|
4
|
-
|
|
5
|
-
- Add support for secrets loading from SECRET_ARN [#327](https://github.com/friggframework/frigg/pull/327) ([@seanspeaks](https://github.com/seanspeaks))
|
|
6
|
-
- Adding support for secrets loading ([@seanspeaks](https://github.com/seanspeaks))
|
|
7
|
-
|
|
8
|
-
#### Authors: 1
|
|
9
|
-
|
|
10
|
-
- Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# v1.2.1 (Thu Aug 08 2024)
|
|
15
|
-
|
|
16
|
-
#### 🐛 Bug Fix
|
|
17
|
-
|
|
18
|
-
- Fix bug during local running [#326](https://github.com/friggframework/frigg/pull/326) ([@seanspeaks](https://github.com/seanspeaks))
|
|
19
|
-
- Adding toJSON so that the descriminator decorator will be evaluated/added to the mongoose model (currently undefined on initialization and first invocation) ([@seanspeaks](https://github.com/seanspeaks))
|
|
20
|
-
|
|
21
|
-
#### Authors: 1
|
|
22
|
-
|
|
23
|
-
- Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
1
|
# v1.2.0 (Tue Aug 06 2024)
|
|
28
2
|
|
|
29
3
|
:tada: This release contains work from a new contributor! :tada:
|
package/core/create-handler.js
CHANGED
|
@@ -3,7 +3,6 @@ require('source-map-support').install();
|
|
|
3
3
|
|
|
4
4
|
const { connectToDatabase } = require('../database/mongo');
|
|
5
5
|
const { initDebugLog, flushDebugLog } = require('../logs');
|
|
6
|
-
const { secretsToEnv } = require('./secrets-to-env');
|
|
7
6
|
|
|
8
7
|
const createHandler = (optionByName = {}) => {
|
|
9
8
|
const {
|
|
@@ -21,15 +20,6 @@ const createHandler = (optionByName = {}) => {
|
|
|
21
20
|
try {
|
|
22
21
|
initDebugLog(eventName, event);
|
|
23
22
|
|
|
24
|
-
const requestMethod = event.httpMethod;
|
|
25
|
-
const requestPath = event.path;
|
|
26
|
-
if (requestMethod && requestPath) {
|
|
27
|
-
console.info(`${requestMethod} ${requestPath}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// If enabled (i.e. if SECRET_ARN is set in process.env) Fetch secrets from AWS Secrets Manager, and set them as environment variables.
|
|
31
|
-
await secretsToEnv();
|
|
32
|
-
|
|
33
23
|
// Helps mongoose reuse the connection. Lowers response times.
|
|
34
24
|
context.callbackWaitsForEmptyEventLoop = false;
|
|
35
25
|
|
|
@@ -27,9 +27,7 @@ class IntegrationBase {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
//psuedo delegate for backwards compatability
|
|
30
|
-
async receiveNotification(notifier, delegateString, object = null) {
|
|
31
|
-
|
|
32
|
-
}
|
|
30
|
+
async receiveNotification(notifier, delegateString, object = null) {}
|
|
33
31
|
|
|
34
32
|
async notify(delegateString, object = null) {
|
|
35
33
|
if (!this.delegateTypes.includes(delegateString)) {
|
|
@@ -37,11 +35,7 @@ class IntegrationBase {
|
|
|
37
35
|
`delegateString:${delegateString} is not defined in delegateTypes`
|
|
38
36
|
);
|
|
39
37
|
}
|
|
40
|
-
return this.receiveNotification(
|
|
41
|
-
this,
|
|
42
|
-
delegateString,
|
|
43
|
-
object
|
|
44
|
-
);
|
|
38
|
+
return this.receiveNotification(this, delegateString, object);
|
|
45
39
|
}
|
|
46
40
|
|
|
47
41
|
async validateConfig() {
|
|
@@ -130,8 +124,6 @@ class IntegrationBase {
|
|
|
130
124
|
return this.userActions;
|
|
131
125
|
}
|
|
132
126
|
|
|
133
|
-
|
|
134
|
-
|
|
135
127
|
/**
|
|
136
128
|
* CHILDREN CAN OVERRIDE THESE CONFIGURATION METHODS
|
|
137
129
|
*/
|
|
@@ -141,10 +133,9 @@ class IntegrationBase {
|
|
|
141
133
|
return this.record;
|
|
142
134
|
}
|
|
143
135
|
|
|
144
|
-
async onUpdate(params) {
|
|
145
|
-
}
|
|
136
|
+
async onUpdate(params) {}
|
|
146
137
|
|
|
147
|
-
async onDelete(params) {
|
|
138
|
+
async onDelete(params) {}
|
|
148
139
|
|
|
149
140
|
async getConfigOptions() {
|
|
150
141
|
const options = {
|
|
@@ -158,8 +149,8 @@ class IntegrationBase {
|
|
|
158
149
|
const options = {
|
|
159
150
|
jsonSchema: {},
|
|
160
151
|
uiSchema: {},
|
|
161
|
-
}
|
|
162
|
-
return options
|
|
152
|
+
};
|
|
153
|
+
return options;
|
|
163
154
|
}
|
|
164
155
|
|
|
165
156
|
async getUserActions() {
|
|
@@ -170,16 +161,16 @@ class IntegrationBase {
|
|
|
170
161
|
const options = {
|
|
171
162
|
jsonSchema: {},
|
|
172
163
|
uiSchema: {},
|
|
173
|
-
}
|
|
174
|
-
return options
|
|
164
|
+
};
|
|
165
|
+
return options;
|
|
175
166
|
}
|
|
176
167
|
|
|
177
168
|
async refreshActionOptions(params) {
|
|
178
169
|
const options = {
|
|
179
170
|
jsonSchema: {},
|
|
180
171
|
uiSchema: {},
|
|
181
|
-
}
|
|
182
|
-
return options
|
|
172
|
+
};
|
|
173
|
+
return options;
|
|
183
174
|
}
|
|
184
175
|
}
|
|
185
176
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
const { Entity } = require(
|
|
1
|
+
const { Entity } = require("./entity");
|
|
2
2
|
const { Auther } = require('./auther');
|
|
3
3
|
|
|
4
4
|
class ModuleFactory {
|
|
5
5
|
constructor(...params) {
|
|
6
6
|
this.moduleDefinitions = params;
|
|
7
|
-
this.moduleTypes = this.moduleDefinitions.map(
|
|
7
|
+
this.moduleTypes = this.moduleDefinitions.map(
|
|
8
|
+
(def) => def.moduleName
|
|
9
|
+
);
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
async getEntitiesForUser(userId) {
|
|
@@ -12,7 +14,7 @@ class ModuleFactory {
|
|
|
12
14
|
for (const moduleDefinition of this.moduleDefinitions) {
|
|
13
15
|
const moduleInstance = await Auther.getInstance({
|
|
14
16
|
userId,
|
|
15
|
-
definition: moduleDefinition
|
|
17
|
+
definition: moduleDefinition
|
|
16
18
|
});
|
|
17
19
|
const list = await moduleInstance.getEntitiesForUserId(userId);
|
|
18
20
|
results.push(...list);
|
|
@@ -25,36 +27,33 @@ class ModuleFactory {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
getModuleDefinitionFromTypeName(typeName) {
|
|
28
|
-
return
|
|
30
|
+
return
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
|
|
31
34
|
async getModuleInstanceFromEntityId(entityId, userId) {
|
|
32
35
|
const entity = await Entity.findById(entityId);
|
|
33
36
|
const moduleDefinition = this.moduleDefinitions.find(
|
|
34
|
-
(def) =>
|
|
35
|
-
|
|
36
|
-
Auther.getEntityModelFromDefinition(def).modelName
|
|
37
|
-
);
|
|
37
|
+
(def) => entity['__t'] === Auther.getEntityModelFromDefinition(def).modelName
|
|
38
|
+
)
|
|
38
39
|
if (!moduleDefinition) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
'Module definition not found for entity type: ' + entity['__t']
|
|
41
|
-
);
|
|
40
|
+
throw new Error('Module definition not found for entity type: ' + entity['__t']);
|
|
42
41
|
}
|
|
43
42
|
return await Auther.getInstance({
|
|
44
43
|
userId,
|
|
45
44
|
entityId,
|
|
46
|
-
definition: moduleDefinition
|
|
45
|
+
definition: moduleDefinition
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
const moduleDefinition =
|
|
49
|
+
async getInstanceFromTypeName(typeName, userId) {
|
|
50
|
+
const moduleDefinition =this.moduleDefinitions.find(
|
|
52
51
|
(def) => def.getName() === typeName
|
|
53
52
|
);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
return await Auther.getInstance({
|
|
54
|
+
userId,
|
|
55
|
+
definition: moduleDefinition
|
|
56
|
+
});
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0--canary.325.7243e56.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@hapi/boom": "^10.0.1",
|
|
7
7
|
"aws-sdk": "^2.1200.0",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"node-fetch": "^2.6.7"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@friggframework/eslint-config": "
|
|
19
|
-
"@friggframework/prettier-config": "
|
|
20
|
-
"@friggframework/test": "
|
|
18
|
+
"@friggframework/eslint-config": "1.3.0--canary.325.7243e56.0",
|
|
19
|
+
"@friggframework/prettier-config": "1.3.0--canary.325.7243e56.0",
|
|
20
|
+
"@friggframework/test": "1.3.0--canary.325.7243e56.0",
|
|
21
21
|
"@types/lodash": "^4.14.191",
|
|
22
22
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
23
23
|
"chai": "^4.3.6",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/friggframework/frigg#readme",
|
|
50
50
|
"description": "",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "7243e56239ceb34e90337e47a34bc14d533fad26"
|
|
52
52
|
}
|
package/core/secrets-to-env.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const getSecretValue = async () => {
|
|
2
|
-
console.log('Fetching secrets...');
|
|
3
|
-
|
|
4
|
-
const httpPort = process.env.PARAMETERS_SECRETS_EXTENSION_HTTP_PORT || 2773;
|
|
5
|
-
const url = `http://localhost:${httpPort}/secretsmanager/get?secretId=${encodeURIComponent(
|
|
6
|
-
process.env.SECRET_ARN
|
|
7
|
-
)}`;
|
|
8
|
-
const options = {
|
|
9
|
-
headers: {
|
|
10
|
-
'X-Aws-Parameters-Secrets-Token': process.env.AWS_SESSION_TOKEN,
|
|
11
|
-
},
|
|
12
|
-
method: 'GET',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const response = await fetch(url, options);
|
|
16
|
-
|
|
17
|
-
if (!response.ok) {
|
|
18
|
-
const json = await response.json().catch((err) => err.message);
|
|
19
|
-
console.error('Invalid response - response:', JSON.stringify(response));
|
|
20
|
-
console.error('Invalid response - json:', json);
|
|
21
|
-
throw new Error(`Invalid ${response.status} response`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const result = await response.json();
|
|
25
|
-
|
|
26
|
-
if (!result) {
|
|
27
|
-
throw new Error('Error getting secret', result);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return JSON.parse(result.SecretString);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const transformSecrets = (secrets) => {
|
|
34
|
-
Object.keys(secrets).forEach((key) => {
|
|
35
|
-
process.env[key] = secrets[key];
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Middleware that gets the secrets from Lambda layer and transform into environment variables.
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
const secretsToEnv = async () => {
|
|
44
|
-
if (!process.env.SECRET_ARN) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
console.log('Secrets to env');
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const secrets = await getSecretValue();
|
|
51
|
-
transformSecrets(secrets);
|
|
52
|
-
|
|
53
|
-
return secrets;
|
|
54
|
-
} catch (err) {
|
|
55
|
-
throw err;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
module.exports = {
|
|
60
|
-
secretsToEnv,
|
|
61
|
-
};
|