@friggframework/core 1.3.0--canary.325.891353e.0 → 2.0.0-next.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 CHANGED
@@ -1,3 +1,29 @@
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
+
1
27
  # v1.2.0 (Tue Aug 06 2024)
2
28
 
3
29
  :tada: This release contains work from a new contributor! :tada:
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  The `frigg-core` package is the heart of the Frigg Framework. It contains the core functionality and essential modules required to build and maintain integrations at scale.
4
4
 
5
+
5
6
  ## Table of Contents
6
7
 
7
8
  - [Introduction](#introduction)
@@ -27,6 +28,7 @@ The Frigg Core package provides the foundational components and utilities for th
27
28
  - **Logging**: Structured logging utilities.
28
29
  - **Module Plugin**: Plugin system for extending core functionality.
29
30
  - **Syncs**: Synchronization utilities for data consistency.
31
+ - **Infrastructure**: Frigg reads through your integration definitions and auto-generates the infrastructure your code needs to run smoothly.
30
32
 
31
33
  ## Installation
32
34
 
@@ -64,6 +66,7 @@ The frigg-core package is organized into several modules:
64
66
  - **Logs**: @friggframework/core/logs
65
67
  - **Module Plugin**: @friggframework/core/module-plugin
66
68
  - **Syncs**: @friggframework/core/syncs
69
+ - **Infrastructure**: @friggframework/core/infrastructure
67
70
 
68
71
 
69
72
  Each module provides specific functionality and can be imported individually as needed.
@@ -3,6 +3,7 @@ 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');
6
7
 
7
8
  const createHandler = (optionByName = {}) => {
8
9
  const {
@@ -20,6 +21,15 @@ const createHandler = (optionByName = {}) => {
20
21
  try {
21
22
  initDebugLog(eventName, event);
22
23
 
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
+
23
33
  // Helps mongoose reuse the connection. Lowers response times.
24
34
  context.callbackWaitsForEmptyEventLoop = false;
25
35
 
@@ -0,0 +1,61 @@
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
+ };
@@ -1,12 +1,10 @@
1
- const { Entity } = require("./entity");
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(
8
- (def) => def.moduleName
9
- );
7
+ this.moduleTypes = this.moduleDefinitions.map((def) => def.moduleName);
10
8
  }
11
9
 
12
10
  async getEntitiesForUser(userId) {
@@ -14,7 +12,7 @@ class ModuleFactory {
14
12
  for (const moduleDefinition of this.moduleDefinitions) {
15
13
  const moduleInstance = await Auther.getInstance({
16
14
  userId,
17
- definition: moduleDefinition
15
+ definition: moduleDefinition,
18
16
  });
19
17
  const list = await moduleInstance.getEntitiesForUserId(userId);
20
18
  results.push(...list);
@@ -27,33 +25,36 @@ class ModuleFactory {
27
25
  }
28
26
 
29
27
  getModuleDefinitionFromTypeName(typeName) {
30
- return
28
+ return;
31
29
  }
32
30
 
33
-
34
31
  async getModuleInstanceFromEntityId(entityId, userId) {
35
32
  const entity = await Entity.findById(entityId);
36
33
  const moduleDefinition = this.moduleDefinitions.find(
37
- (def) => entity['__t'] === Auther.getEntityModelFromDefinition(def).modelName
38
- )
34
+ (def) =>
35
+ entity.toJSON()['__t'] ===
36
+ Auther.getEntityModelFromDefinition(def).modelName
37
+ );
39
38
  if (!moduleDefinition) {
40
- throw new Error('Module definition not found for entity type: ' + entity['__t']);
39
+ throw new Error(
40
+ 'Module definition not found for entity type: ' + entity['__t']
41
+ );
41
42
  }
42
43
  return await Auther.getInstance({
43
44
  userId,
44
45
  entityId,
45
- definition: moduleDefinition
46
+ definition: moduleDefinition,
46
47
  });
47
48
  }
48
49
 
49
- async getInstanceFromTypeName(typeName, userId) {
50
- const moduleDefinition =this.moduleDefinitions.find(
50
+ async getInstanceFromTypeName(typeName, userId) {
51
+ const moduleDefinition = this.moduleDefinitions.find(
51
52
  (def) => def.getName() === typeName
52
53
  );
53
- return await Auther.getInstance({
54
- userId,
55
- definition: moduleDefinition
56
- });
54
+ return await Auther.getInstance({
55
+ userId,
56
+ definition: moduleDefinition,
57
+ });
57
58
  }
58
59
  }
59
60
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "1.3.0--canary.325.891353e.0",
4
+ "version": "2.0.0-next.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": "1.3.0--canary.325.891353e.0",
19
- "@friggframework/prettier-config": "1.3.0--canary.325.891353e.0",
20
- "@friggframework/test": "1.3.0--canary.325.891353e.0",
18
+ "@friggframework/eslint-config": "^2.0.0-next.0",
19
+ "@friggframework/prettier-config": "^2.0.0-next.0",
20
+ "@friggframework/test": "^2.0.0-next.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": "891353e441b0a025feb1d24a734ce0f8371101d0"
51
+ "gitHead": "e37f577d3c14f8eed6584517830c6c61815cf759"
52
52
  }