@friggframework/core 1.1.6--canary.307.644a753.0 → 1.1.7--canary.359.1946bb6.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,100 @@
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
+ # v1.2.0 (Tue Aug 06 2024)
28
+
29
+ :tada: This release contains work from a new contributor! :tada:
30
+
31
+ Thank you, Daniel Klotz ([@d-klotz](https://github.com/d-klotz)), for all your work!
32
+
33
+ #### 🐛 Bug Fix
34
+
35
+ - Add READMEs that will need updating, but for version releasing [#324](https://github.com/friggframework/frigg/pull/324) ([@seanspeaks](https://github.com/seanspeaks))
36
+ - Add READMEs that will need updating, but for version releasing ([@seanspeaks](https://github.com/seanspeaks))
37
+ - small update to integration testing / tooling [#304](https://github.com/friggframework/frigg/pull/304) ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
38
+ - chore: bump deprecated npm package versions [#323](https://github.com/friggframework/frigg/pull/323) ([@d-klotz](https://github.com/d-klotz) [@seanspeaks](https://github.com/seanspeaks))
39
+ - chore: bump deprecated package versions ([@d-klotz](https://github.com/d-klotz))
40
+ - Bump version to: v1.1.8 \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
41
+ - remove comment ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
42
+ - use the factory methods for creating the mock integration so that everything is set up (mostly events and userActions) ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
43
+ - fix imports to not inadvertently call loadInstalledModules ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
44
+ - Bump version to: v1.1.5 \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
45
+
46
+ #### Authors: 3
47
+
48
+ - [@MichaelRyanWebber](https://github.com/MichaelRyanWebber)
49
+ - Daniel Klotz ([@d-klotz](https://github.com/d-klotz))
50
+ - Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
51
+
52
+ ---
53
+
54
+ # v1.1.8 (Thu Jul 18 2024)
55
+
56
+ #### 🐛 Bug Fix
57
+
58
+ - Revert open to support commonjs [#319](https://github.com/friggframework/frigg/pull/319) ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
59
+ - Bump version to: v1.1.6 \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
60
+
61
+ #### Authors: 2
62
+
63
+ - [@MichaelRyanWebber](https://github.com/MichaelRyanWebber)
64
+ - Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
65
+
66
+ ---
67
+
68
+ # v1.1.7 (Mon Jul 15 2024)
69
+
70
+ #### 🐛 Bug Fix
71
+
72
+ - getAuthorizationRequirements() async [#318](https://github.com/friggframework/frigg/pull/318) ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
73
+ - getAuthorizationRequirements should be async, though it will only occasionally need to make requests ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
74
+ - Bump version to: v1.1.6 \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
75
+
76
+ #### Authors: 2
77
+
78
+ - [@MichaelRyanWebber](https://github.com/MichaelRyanWebber)
79
+ - Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
80
+
81
+ ---
82
+
83
+ # v1.1.6 (Fri Apr 26 2024)
84
+
85
+ #### 🐛 Bug Fix
86
+
87
+ - Small fix to validation errors and cleanup [#307](https://github.com/friggframework/frigg/pull/307) ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
88
+ - remove excess files to centralize jest config and cleanup ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
89
+ - Bump version to: v1.1.5 \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
90
+
91
+ #### Authors: 2
92
+
93
+ - [@MichaelRyanWebber](https://github.com/MichaelRyanWebber)
94
+ - Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
95
+
96
+ ---
97
+
1
98
  # v1.1.5 (Tue Apr 09 2024)
2
99
 
3
100
  #### 🐛 Bug Fix
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Frigg Core
2
+
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
+
5
+
6
+ ## Table of Contents
7
+
8
+ - [Introduction](#introduction)
9
+ - [Features](#features)
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Modules](#modules)
13
+ - [Contributing](#contributing)
14
+ - [License](#license)
15
+
16
+ ## Introduction
17
+
18
+ The Frigg Core package provides the foundational components and utilities for the Frigg Framework. It is designed to be modular, extensible, and easy to integrate with other packages in the Frigg ecosystem.
19
+
20
+ ## Features
21
+
22
+ - **Associations**: Manage relationships between different entities.
23
+ - **Database**: Database utilities and connectors.
24
+ - **Encryption**: Secure data encryption and decryption.
25
+ - **Error Handling**: Standardized error handling mechanisms.
26
+ - **Integrations**: Tools for building and managing integrations.
27
+ - **Lambda**: Utilities for AWS Lambda functions.
28
+ - **Logging**: Structured logging utilities.
29
+ - **Module Plugin**: Plugin system for extending core functionality.
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.
32
+
33
+ ## Installation
34
+
35
+ To install the `frigg-core` package, use npm or yarn:
36
+
37
+ ```sh
38
+ npm install @friggframework/core
39
+ # or
40
+ yarn add @friggframework/core
41
+ ```
42
+ ## Usage
43
+ Here's a basic example of how to use the frigg-core package:
44
+ ```javascript
45
+ const { encrypt, decrypt } = require('@friggframework/core/encrypt');
46
+ const { logInfo } = require('@friggframework/core/logs');
47
+
48
+ const secret = 'mySecret';
49
+ const encrypted = encrypt(secret);
50
+ const decrypted = decrypt(encrypted);
51
+
52
+ logInfo(`Encrypted: ${encrypted}`);
53
+ logInfo(`Decrypted: ${decrypted}`);
54
+ ```
55
+
56
+ ## Modules
57
+
58
+ The frigg-core package is organized into several modules:
59
+
60
+ - **Associations**: @friggframework/core/associations
61
+ - **Database**: @friggframework/core/database
62
+ - **Encryption**: @friggframework/core/encrypt
63
+ - **Errors**: @friggframework/core/errors
64
+ - **Integrations**: @friggframework/core/integrations
65
+ - **Lambda**: @friggframework/core/lambda
66
+ - **Logs**: @friggframework/core/logs
67
+ - **Module Plugin**: @friggframework/core/module-plugin
68
+ - **Syncs**: @friggframework/core/syncs
69
+ - **Infrastructure**: @friggframework/core/infrastructure
70
+
71
+
72
+ Each module provides specific functionality and can be imported individually as needed.
73
+
74
+ ## Contributing
75
+
76
+ We welcome contributions from the community! Please read our contributing guide to get started. Make sure to follow our code of conduct and use the provided pull request template.
77
+
78
+ ## License
79
+
80
+ This project is licensed under the MIT License. See the LICENSE.md file for details.
81
+
82
+ ---
83
+ Thank you for using Frigg Core! If you have any questions or need further assistance, feel free to reach out to our community on Slack or check out our GitHub issues page.
@@ -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
+ };
@@ -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
 
@@ -87,18 +87,6 @@ class IntegrationFactory {
87
87
  }
88
88
 
89
89
  async createIntegration(entities, userId, config) {
90
- // verify entity ids belong to the user
91
- // for (const id of entities) {
92
- // const entity = await Entity.findById(id);
93
- // if (!entity) {
94
- // throw new Error(`Entity with ID ${id} does not exist.`);
95
- // }
96
- // if (entity.user.toString() !== userId.toString()) {
97
- // throw new Error('one or more the entities do not belong to the user');
98
- // }
99
- // }
100
-
101
- // build integration
102
90
  const integrationRecord = await IntegrationModel.create({
103
91
  entities: entities,
104
92
  user: userId,
@@ -80,7 +80,6 @@ function setIntegrationRoutes(router, factory, getUserId) {
80
80
  params.entities,
81
81
  getUserId(req),
82
82
  params.config,
83
- moduleFactory
84
83
  );
85
84
 
86
85
  // post integration initialization
@@ -2,7 +2,8 @@ const _ = require('lodash');
2
2
  const { mongoose } = require('../../database/mongoose');
3
3
  const { expect } = require('chai');
4
4
  const { IntegrationBase } = require("../integration-base");
5
- const {Credential, Entity} = require('../../module-plugin');
5
+ const {Credential} = require('../../module-plugin/credential');
6
+ const {Entity} = require('../../module-plugin/entity');
6
7
  const { IntegrationMapping } = require('../integration-mapping')
7
8
  const {IntegrationModel} = require("../integration-model");
8
9
 
@@ -203,7 +203,7 @@ class Auther extends Delegate {
203
203
  return valid;
204
204
  }
205
205
 
206
- getAuthorizationRequirements(params) {
206
+ async getAuthorizationRequirements(params) {
207
207
  // TODO: How can this be more helpful both to implement and consume
208
208
  // this function must return a dictionary with the following format
209
209
  // node only url key is required. Data would be used for Base Authentication
@@ -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.1.6--canary.307.644a753.0",
4
+ "version": "1.1.7--canary.359.1946bb6.0",
5
5
  "dependencies": {
6
6
  "@hapi/boom": "^10.0.1",
7
7
  "aws-sdk": "^2.1200.0",
@@ -15,22 +15,21 @@
15
15
  "node-fetch": "^2.6.7"
16
16
  },
17
17
  "devDependencies": {
18
- "@friggframework/eslint-config": "1.1.6--canary.307.644a753.0",
19
- "@friggframework/prettier-config": "1.1.6--canary.307.644a753.0",
20
- "@friggframework/test": "1.1.6--canary.307.644a753.0",
18
+ "@friggframework/eslint-config": "1.1.7--canary.359.1946bb6.0",
19
+ "@friggframework/prettier-config": "1.1.7--canary.359.1946bb6.0",
20
+ "@friggframework/test": "1.1.7--canary.359.1946bb6.0",
21
21
  "@types/lodash": "^4.14.191",
22
- "@typescript-eslint/eslint-plugin": "^5.55.0",
22
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
23
23
  "chai": "^4.3.6",
24
- "eslint": "^8.36.0",
25
- "eslint-config-standard-with-typescript": "^34.0.1",
26
- "eslint-plugin-import": "^2.27.5",
27
- "eslint-plugin-n": "^15.6.1",
28
- "eslint-plugin-promise": "^6.1.1",
29
- "jest": "^28.1.3",
24
+ "eslint": "^8.22.0",
25
+ "eslint-plugin-import": "^2.29.1",
26
+ "eslint-plugin-n": "^17.10.2",
27
+ "eslint-plugin-promise": "^7.0.0",
28
+ "jest": "^29.7.0",
30
29
  "jest-runner-groups": "^2.2.0",
31
30
  "mongodb-memory-server": "^8.9.0",
32
31
  "prettier": "^2.8.5",
33
- "sinon": "^14.0.0",
32
+ "sinon": "^16.1.1",
34
33
  "typescript": "^5.0.2"
35
34
  },
36
35
  "scripts": {
@@ -49,5 +48,5 @@
49
48
  },
50
49
  "homepage": "https://github.com/friggframework/frigg#readme",
51
50
  "description": "",
52
- "gitHead": "644a753c7290d814fae18a4f8b815ae650c0d936"
51
+ "gitHead": "1946bb6a964605c8b3482683bb53eed8d6ee2da6"
53
52
  }