@friggframework/core 1.2.0-canary.293.5731c31.0 → 2.0.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 +22 -0
- package/encrypt/encrypt.test.js +1 -1
- package/index.js +3 -11
- package/integrations/index.js +1 -4
- package/integrations/jest-setup.js +1 -1
- package/integrations/jest-teardown.js +1 -1
- package/logs/logger.test.js +1 -1
- package/module-plugin/index.js +1 -5
- package/module-plugin/jest-setup.js +1 -1
- package/module-plugin/jest-teardown.js +1 -1
- package/package.json +5 -3
- package/integrations/mock-integration.js +0 -83
- package/module-plugin/auther-definition-method-tester.js +0 -45
- package/module-plugin/auther-definition-tester.js +0 -121
- package/module-plugin/bump3.txt +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# v2.0.0 (Sat Mar 30 2024)
|
|
2
|
+
|
|
3
|
+
#### 🚀 Enhancement
|
|
4
|
+
|
|
5
|
+
- Package redo [#294](https://github.com/friggframework/frigg/pull/294) ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
|
|
6
|
+
|
|
7
|
+
#### 🐛 Bug Fix
|
|
8
|
+
|
|
9
|
+
- update test related imports in core ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
|
|
10
|
+
- missed one ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
|
|
11
|
+
- create test, eslint-config and prettier-config packages as base shared dependencies ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
|
|
12
|
+
- Publish ([@seanspeaks](https://github.com/seanspeaks))
|
|
13
|
+
- Bump node and npm version for the whole repo (Fix CI) [#274](https://github.com/friggframework/frigg/pull/274) ([@seanspeaks](https://github.com/seanspeaks))
|
|
14
|
+
- Bump independent versions \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
|
|
15
|
+
|
|
16
|
+
#### Authors: 2
|
|
17
|
+
|
|
18
|
+
- [@MichaelRyanWebber](https://github.com/MichaelRyanWebber)
|
|
19
|
+
- Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
1
23
|
# v1.1.0 (Wed Mar 20 2024)
|
|
2
24
|
|
|
3
25
|
:tada: This release contains work from new contributors! :tada:
|
package/encrypt/encrypt.test.js
CHANGED
|
@@ -8,7 +8,7 @@ const {
|
|
|
8
8
|
createModel,
|
|
9
9
|
saveTestDocument,
|
|
10
10
|
} = require('./test-encrypt');
|
|
11
|
-
const { TestMongo } = require('@friggframework/
|
|
11
|
+
const { TestMongo } = require('@friggframework/test');
|
|
12
12
|
|
|
13
13
|
const testMongo = new TestMongo();
|
|
14
14
|
const originalEnv = process.env;
|
package/index.js
CHANGED
|
@@ -36,9 +36,7 @@ const {
|
|
|
36
36
|
IntegrationHelper,
|
|
37
37
|
createIntegrationRouter,
|
|
38
38
|
checkRequiredParams,
|
|
39
|
-
createFriggBackend
|
|
40
|
-
createMockIntegration,
|
|
41
|
-
createMockApiObject
|
|
39
|
+
createFriggBackend
|
|
42
40
|
} = require('./integrations/index');
|
|
43
41
|
const { TimeoutCatcher } = require('./lambda/index');
|
|
44
42
|
const {
|
|
@@ -57,9 +55,7 @@ const {
|
|
|
57
55
|
Requester,
|
|
58
56
|
ModuleConstants,
|
|
59
57
|
ModuleFactory,
|
|
60
|
-
Auther
|
|
61
|
-
testAutherDefinition,
|
|
62
|
-
testDefinitionRequiredAuthMethods
|
|
58
|
+
Auther
|
|
63
59
|
} = require('./module-plugin/index');
|
|
64
60
|
|
|
65
61
|
// const {Sync } = require('./syncs/model');
|
|
@@ -107,8 +103,6 @@ module.exports = {
|
|
|
107
103
|
checkRequiredParams,
|
|
108
104
|
createIntegrationRouter,
|
|
109
105
|
createFriggBackend,
|
|
110
|
-
createMockIntegration,
|
|
111
|
-
createMockApiObject,
|
|
112
106
|
// lambda
|
|
113
107
|
TimeoutCatcher,
|
|
114
108
|
// logs
|
|
@@ -126,7 +120,5 @@ module.exports = {
|
|
|
126
120
|
Requester,
|
|
127
121
|
ModuleConstants,
|
|
128
122
|
ModuleFactory,
|
|
129
|
-
Auther
|
|
130
|
-
testAutherDefinition,
|
|
131
|
-
testDefinitionRequiredAuthMethods
|
|
123
|
+
Auther
|
|
132
124
|
}
|
package/integrations/index.js
CHANGED
|
@@ -5,7 +5,6 @@ const { IntegrationMapping } = require('./integration-mapping');
|
|
|
5
5
|
const { IntegrationFactory, IntegrationHelper } = require('./integration-factory');
|
|
6
6
|
const { createIntegrationRouter, checkRequiredParams } = require('./integration-router');
|
|
7
7
|
const { createFriggBackend } = require('./create-frigg-backend');
|
|
8
|
-
const { createMockApiObject, createMockIntegration } = require('./mock-integration');
|
|
9
8
|
|
|
10
9
|
module.exports = {
|
|
11
10
|
IntegrationBase,
|
|
@@ -16,7 +15,5 @@ module.exports = {
|
|
|
16
15
|
IntegrationHelper,
|
|
17
16
|
createIntegrationRouter,
|
|
18
17
|
checkRequiredParams,
|
|
19
|
-
createFriggBackend
|
|
20
|
-
createMockIntegration,
|
|
21
|
-
createMockApiObject
|
|
18
|
+
createFriggBackend
|
|
22
19
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const { globalSetup } = require('@friggframework/
|
|
1
|
+
const { globalSetup } = require('@friggframework/test');
|
|
2
2
|
module.exports = globalSetup;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const { globalTeardown } = require('@friggframework/
|
|
1
|
+
const { globalTeardown } = require('@friggframework/test');
|
|
2
2
|
module.exports = globalTeardown;
|
package/logs/logger.test.js
CHANGED
package/module-plugin/index.js
CHANGED
|
@@ -9,8 +9,6 @@ const { Requester } = require('./requester/requester');
|
|
|
9
9
|
const { ModuleConstants } = require('./ModuleConstants');
|
|
10
10
|
const { ModuleFactory } = require('./module-factory');
|
|
11
11
|
const { Auther } = require('./auther');
|
|
12
|
-
const { testAutherDefinition } = require('./auther-definition-tester');
|
|
13
|
-
const { testDefinitionRequiredAuthMethods } = require('./auther-definition-method-tester');
|
|
14
12
|
|
|
15
13
|
module.exports = {
|
|
16
14
|
Credential,
|
|
@@ -23,7 +21,5 @@ module.exports = {
|
|
|
23
21
|
Requester,
|
|
24
22
|
ModuleConstants,
|
|
25
23
|
ModuleFactory,
|
|
26
|
-
Auther
|
|
27
|
-
testAutherDefinition,
|
|
28
|
-
testDefinitionRequiredAuthMethods
|
|
24
|
+
Auther
|
|
29
25
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const { globalTeardown } = require('@friggframework/
|
|
1
|
+
const { globalTeardown } = require('@friggframework/test');
|
|
2
2
|
module.exports = globalTeardown;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@hapi/boom": "^10.0.1",
|
|
7
7
|
"aws-sdk": "^2.1200.0",
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"node-fetch": "^2.6.7"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@friggframework/
|
|
18
|
+
"@friggframework/eslint-config": "^2.0.0",
|
|
19
|
+
"@friggframework/prettier-config": "^2.0.0",
|
|
20
|
+
"@friggframework/test": "^2.0.0",
|
|
19
21
|
"@types/lodash": "^4.14.191",
|
|
20
22
|
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
21
23
|
"chai": "^4.3.6",
|
|
@@ -47,5 +49,5 @@
|
|
|
47
49
|
},
|
|
48
50
|
"homepage": "https://github.com/friggframework/frigg#readme",
|
|
49
51
|
"description": "",
|
|
50
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "d56e109150e02915b63a47ecb87483fbd9b0776e"
|
|
51
53
|
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const { Auther, Credential, Entity } = require('../module-plugin')
|
|
2
|
-
const { IntegrationModel } = require('./integration-model');
|
|
3
|
-
const { createObjectId } = require('../database');
|
|
4
|
-
|
|
5
|
-
async function createMockIntegration(IntegrationClassDef, userId = null, config = {},) {
|
|
6
|
-
const integration = new IntegrationClassDef();
|
|
7
|
-
userId = userId || createObjectId();
|
|
8
|
-
integration.delegateTypes.push(...IntegrationClassDef.Config.events)
|
|
9
|
-
|
|
10
|
-
const insertOptions = {
|
|
11
|
-
new: true,
|
|
12
|
-
upsert: true,
|
|
13
|
-
setDefaultsOnInsert: true,
|
|
14
|
-
}
|
|
15
|
-
const user = {user: userId}
|
|
16
|
-
|
|
17
|
-
const credential = await Credential.findOneAndUpdate(
|
|
18
|
-
user,
|
|
19
|
-
{ $set: user },
|
|
20
|
-
insertOptions
|
|
21
|
-
);
|
|
22
|
-
const entity1 = await Entity.findOneAndUpdate(
|
|
23
|
-
user,
|
|
24
|
-
{
|
|
25
|
-
$set: {
|
|
26
|
-
credential: credential.id,
|
|
27
|
-
user: userId,
|
|
28
|
-
name: 'Test user',
|
|
29
|
-
externalId: '1234567890123456',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
insertOptions
|
|
33
|
-
);
|
|
34
|
-
const entity2 = await Entity.findOneAndUpdate(
|
|
35
|
-
user,
|
|
36
|
-
{
|
|
37
|
-
$set: {
|
|
38
|
-
credential: credential.id,
|
|
39
|
-
user: userId,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
insertOptions
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const entities = [entity1, entity2]
|
|
46
|
-
integration.record = await IntegrationModel.create({
|
|
47
|
-
entities,
|
|
48
|
-
user: userId,
|
|
49
|
-
config: {type: IntegrationClassDef.Config.name, ...config}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
integration.id = integration.record._id
|
|
53
|
-
|
|
54
|
-
for (const i in entities){
|
|
55
|
-
if (Object.entries(IntegrationClassDef.modules).length <= i) break
|
|
56
|
-
const [moduleName, ModuleDef] = Object.entries(IntegrationClassDef.modules)[i];
|
|
57
|
-
const module = await Auther.getInstance({definition: ModuleDef, userId: userId})
|
|
58
|
-
module.entity = entities[i];
|
|
59
|
-
integration[moduleName] = module;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return integration
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function createMockApiObject(jest, api = {}, mockMethodMap) {
|
|
66
|
-
// take in an api class and object with keys that are method names
|
|
67
|
-
// and values which are the mock response (or implementation)
|
|
68
|
-
const clone = (data) => JSON.parse(JSON.stringify(data));
|
|
69
|
-
|
|
70
|
-
for (const [methodName, mockDataOrImplementation] of Object.entries(mockMethodMap)) {
|
|
71
|
-
if (mockDataOrImplementation instanceof Function) {
|
|
72
|
-
api[methodName] = jest.fn(mockDataOrImplementation);
|
|
73
|
-
}
|
|
74
|
-
else if (api[methodName]?.constructor?.name === "AsyncFunction") {
|
|
75
|
-
api[methodName] = jest.fn().mockResolvedValue(clone(mockDataOrImplementation));
|
|
76
|
-
} else {
|
|
77
|
-
api[methodName] = jest.fn().mockReturnValue(clone(mockDataOrImplementation));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return api;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
module.exports = {createMockIntegration, createMockApiObject};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const {flushDebugLog} = require('../logs');
|
|
2
|
-
|
|
3
|
-
async function testDefinitionRequiredAuthMethods(api, definition, authCallbackParams, tokenResponse, userId) {
|
|
4
|
-
|
|
5
|
-
// const response = await definition.getToken(api, authCallbackParams);
|
|
6
|
-
// expect(api.setTokens).toHaveBeenCalled();
|
|
7
|
-
// if (tokenResponse) {
|
|
8
|
-
// expect(response).toMatchObject(tokenResponse);
|
|
9
|
-
// }
|
|
10
|
-
|
|
11
|
-
const entityDetails = await definition.requiredAuthMethods.getEntityDetails(api, authCallbackParams, tokenResponse, userId);
|
|
12
|
-
expect(entityDetails).toHaveProperty('identifiers');
|
|
13
|
-
expect(Object.values(entityDetails.identifiers).length).toBeGreaterThan(0);
|
|
14
|
-
for (const key of Object.keys(entityDetails.identifiers)){
|
|
15
|
-
expect(key).toBeDefined();
|
|
16
|
-
expect(entityDetails.identifiers[key]).toBeDefined();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const credentialDetails = await definition.requiredAuthMethods.getCredentialDetails(api);
|
|
21
|
-
expect(credentialDetails).toHaveProperty('identifiers');
|
|
22
|
-
expect(Object.values(entityDetails.identifiers).length).toBeGreaterThan(0);
|
|
23
|
-
for (const key of Object.keys(entityDetails.identifiers)){
|
|
24
|
-
expect(key).toBeDefined();
|
|
25
|
-
expect(entityDetails.identifiers[key]).toBeDefined();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const successResponse = await definition.requiredAuthMethods.testAuthRequest(api);
|
|
29
|
-
expect(successResponse).toBeTruthy();
|
|
30
|
-
const savedKeys = {};
|
|
31
|
-
for (const key of definition.requiredAuthMethods.apiPropertiesToPersist.credential){
|
|
32
|
-
savedKeys[key] = api[key];
|
|
33
|
-
delete api[key];
|
|
34
|
-
}
|
|
35
|
-
let validAuth = false;
|
|
36
|
-
try {
|
|
37
|
-
if (await definition.requiredAuthMethods.testAuthRequest(api)) validAuth = true;
|
|
38
|
-
} catch (e) {
|
|
39
|
-
flushDebugLog(e);
|
|
40
|
-
}
|
|
41
|
-
expect(validAuth).not.toBeTruthy();
|
|
42
|
-
Object.assign(api, savedKeys);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
module.exports = { testDefinitionRequiredAuthMethods }
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
const { Auther } = require('./auther');
|
|
2
|
-
const { ModuleConstants } = require('./ModuleConstants');
|
|
3
|
-
const { createObjectId,connectToDatabase, disconnectFromDatabase } = require('../database');
|
|
4
|
-
const { createMockApiObject } = require("../integrations/mock-integration");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function testAutherDefinition(definition, mocks) {
|
|
8
|
-
const getModule = async (params) => {
|
|
9
|
-
const module = await Auther.getInstance({
|
|
10
|
-
definition,
|
|
11
|
-
userId: createObjectId(),
|
|
12
|
-
...params,
|
|
13
|
-
});
|
|
14
|
-
if (mocks.tokenResponse) {
|
|
15
|
-
mocks.getTokenFrom = async function(code) {
|
|
16
|
-
await this.setTokens(mocks.tokenResponse);
|
|
17
|
-
return mocks.tokenResponse
|
|
18
|
-
}
|
|
19
|
-
mocks.getTokenFromCode = mocks.getTokenFromCode || mocks.getTokenFrom
|
|
20
|
-
mocks.getTokenFromCodeBasicAuthHeader = mocks.getTokenFromCodeBasicAuthHeader || mocks.getTokenFrom
|
|
21
|
-
mocks.getTokenFromClientCredentials = mocks.getTokenFromClientCredentials || mocks.getTokenFrom
|
|
22
|
-
mocks.getTokenFromUsernamePassword = mocks.getTokenFromUsernamePassword || mocks.getTokenFrom
|
|
23
|
-
}
|
|
24
|
-
if (mocks.refreshResponse) {
|
|
25
|
-
mocks.refreshAccessToken = async function(code) {
|
|
26
|
-
await this.setTokens(mocks.refreshResponse);
|
|
27
|
-
return mocks.refreshResponse
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
module.api = createMockApiObject(jest, module.api, mocks);
|
|
31
|
-
return module
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
describe(`${definition.moduleName} Module Tests`, () => {
|
|
36
|
-
let module, authUrl;
|
|
37
|
-
beforeAll(async () => {
|
|
38
|
-
await connectToDatabase();
|
|
39
|
-
module = await getModule();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
afterAll(async () => {
|
|
43
|
-
await disconnectFromDatabase();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
let requirements, authCallbackParams;
|
|
47
|
-
if (definition.API.requesterType === ModuleConstants.authType.oauth2) {
|
|
48
|
-
authCallbackParams = mocks.authorizeResponse || mocks.authorizeParams;
|
|
49
|
-
describe('getAuthorizationRequirements() test', () => {
|
|
50
|
-
it('should return auth requirements', async () => {
|
|
51
|
-
requirements = module.getAuthorizationRequirements();
|
|
52
|
-
expect(requirements).toBeDefined();
|
|
53
|
-
expect(requirements.type).toEqual(ModuleConstants.authType.oauth2);
|
|
54
|
-
expect(requirements.url).toBeDefined();
|
|
55
|
-
authUrl = requirements.url;
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
} else if (definition.API.requesterType === ModuleConstants.authType.basic) {
|
|
59
|
-
// could also confirm authCallbackParams against the auth requirements
|
|
60
|
-
authCallbackParams = mocks.authorizeParams
|
|
61
|
-
describe('getAuthorizationRequirements() test', () => {
|
|
62
|
-
it('should return auth requirements', async () => {
|
|
63
|
-
requirements = module.getAuthorizationRequirements();
|
|
64
|
-
expect(requirements).toBeDefined();
|
|
65
|
-
expect(requirements.type).toEqual(ModuleConstants.authType.basic);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
} else if (definition.API.requesterType === ModuleConstants.authType.apiKey) {
|
|
69
|
-
// could also confirm authCallbackParams against the auth requirements
|
|
70
|
-
authCallbackParams = mocks.authorizeParams
|
|
71
|
-
describe('getAuthorizationRequirements() test', () => {
|
|
72
|
-
it('should return auth requirements', async () => {
|
|
73
|
-
requirements = module.getAuthorizationRequirements();
|
|
74
|
-
expect(requirements).toBeDefined();
|
|
75
|
-
expect(requirements.type).toEqual(ModuleConstants.authType.apiKey);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
describe('Authorization requests', () => {
|
|
81
|
-
let firstRes;
|
|
82
|
-
it('processAuthorizationCallback()', async () => {
|
|
83
|
-
firstRes = await module.processAuthorizationCallback(authCallbackParams);
|
|
84
|
-
expect(firstRes).toBeDefined();
|
|
85
|
-
expect(firstRes.entity_id).toBeDefined();
|
|
86
|
-
expect(firstRes.credential_id).toBeDefined();
|
|
87
|
-
});
|
|
88
|
-
it('retrieves existing entity on subsequent calls', async () => {
|
|
89
|
-
const res = await module.processAuthorizationCallback(authCallbackParams);
|
|
90
|
-
expect(res).toEqual(firstRes);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('Test credential retrieval and module instantiation', () => {
|
|
95
|
-
it('retrieve by entity id', async () => {
|
|
96
|
-
const newModule = await getModule({
|
|
97
|
-
userId: module.userId,
|
|
98
|
-
entityId: module.entity.id
|
|
99
|
-
});
|
|
100
|
-
expect(newModule).toBeDefined();
|
|
101
|
-
expect(newModule.entity).toBeDefined();
|
|
102
|
-
expect(newModule.credential).toBeDefined();
|
|
103
|
-
expect(await newModule.testAuth()).toBeTruthy();
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('retrieve by credential id', async () => {
|
|
108
|
-
const newModule = await getModule({
|
|
109
|
-
userId: module.userId,
|
|
110
|
-
credentialId: module.credential.id
|
|
111
|
-
});
|
|
112
|
-
expect(newModule).toBeDefined();
|
|
113
|
-
expect(newModule.credential).toBeDefined();
|
|
114
|
-
expect(await newModule.testAuth()).toBeTruthy();
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
module.exports = { testAutherDefinition }
|
|
121
|
-
|
package/module-plugin/bump3.txt
DELETED
|
File without changes
|