@friggframework/devtools 2.0.0--canary.395.c089c7d.0 → 2.0.0--canary.413.52695f8.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.395.c089c7d.0",
4
+ "version": "2.0.0--canary.413.52695f8.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-ec2": "^3.835.0",
7
7
  "@aws-sdk/client-kms": "^3.835.0",
@@ -9,8 +9,8 @@
9
9
  "@babel/eslint-parser": "^7.18.9",
10
10
  "@babel/parser": "^7.25.3",
11
11
  "@babel/traverse": "^7.25.3",
12
- "@friggframework/schemas": "2.0.0--canary.395.c089c7d.0",
13
- "@friggframework/test": "2.0.0--canary.395.c089c7d.0",
12
+ "@friggframework/schemas": "2.0.0--canary.413.52695f8.0",
13
+ "@friggframework/test": "2.0.0--canary.413.52695f8.0",
14
14
  "@hapi/boom": "^10.0.1",
15
15
  "@inquirer/prompts": "^5.3.8",
16
16
  "axios": "^1.7.2",
@@ -32,8 +32,8 @@
32
32
  "serverless-http": "^2.7.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@friggframework/eslint-config": "2.0.0--canary.395.c089c7d.0",
36
- "@friggframework/prettier-config": "2.0.0--canary.395.c089c7d.0",
35
+ "@friggframework/eslint-config": "2.0.0--canary.413.52695f8.0",
36
+ "@friggframework/prettier-config": "2.0.0--canary.413.52695f8.0",
37
37
  "prettier": "^2.7.1",
38
38
  "serverless": "3.39.0",
39
39
  "serverless-dotenv-plugin": "^6.0.0",
@@ -65,5 +65,5 @@
65
65
  "publishConfig": {
66
66
  "access": "public"
67
67
  },
68
- "gitHead": "c089c7d850dab85bd2b1619d27e67e6761144191"
68
+ "gitHead": "52695f82fbf27b46b7c7bfac98a611b676c0b0e2"
69
69
  }
@@ -0,0 +1,125 @@
1
+ const {
2
+ Auther,
3
+ ModuleConstants,
4
+ createObjectId,
5
+ connectToDatabase,
6
+ disconnectFromDatabase,
7
+ } = require('@friggframework/core');
8
+ const { createMockApiObject } = require("./mock-integration");
9
+
10
+
11
+ function testAutherDefinition(definition, mocks) {
12
+ const getModule = async (params) => {
13
+ const module = await Auther.getInstance({
14
+ definition,
15
+ userId: createObjectId(),
16
+ ...params,
17
+ });
18
+ if (mocks.tokenResponse) {
19
+ mocks.getTokenFrom = async function(code) {
20
+ await this.setTokens(mocks.tokenResponse);
21
+ return mocks.tokenResponse
22
+ }
23
+ mocks.getTokenFromCode = mocks.getTokenFromCode || mocks.getTokenFrom
24
+ mocks.getTokenFromCodeBasicAuthHeader = mocks.getTokenFromCodeBasicAuthHeader || mocks.getTokenFrom
25
+ mocks.getTokenFromClientCredentials = mocks.getTokenFromClientCredentials || mocks.getTokenFrom
26
+ mocks.getTokenFromUsernamePassword = mocks.getTokenFromUsernamePassword || mocks.getTokenFrom
27
+ }
28
+ if (mocks.refreshResponse) {
29
+ mocks.refreshAccessToken = async function(code) {
30
+ await this.setTokens(mocks.refreshResponse);
31
+ return mocks.refreshResponse
32
+ }
33
+ }
34
+ module.api = createMockApiObject(jest, module.api, mocks);
35
+ return module
36
+ }
37
+
38
+
39
+ describe(`${definition.moduleName} Module Tests`, () => {
40
+ let module, authUrl;
41
+ beforeAll(async () => {
42
+ await connectToDatabase();
43
+ module = await getModule();
44
+ });
45
+
46
+ afterAll(async () => {
47
+ await disconnectFromDatabase();
48
+ });
49
+
50
+ let requirements, authCallbackParams;
51
+ if (definition.API.requesterType === ModuleConstants.authType.oauth2) {
52
+ authCallbackParams = mocks.authorizeResponse || mocks.authorizeParams;
53
+ describe('getAuthorizationRequirements() test', () => {
54
+ it('should return auth requirements', async () => {
55
+ requirements = await module.getAuthorizationRequirements();
56
+ expect(requirements).toBeDefined();
57
+ expect(requirements.type).toEqual(ModuleConstants.authType.oauth2);
58
+ expect(requirements.url).toBeDefined();
59
+ authUrl = requirements.url;
60
+ });
61
+ });
62
+ } else if (definition.API.requesterType === ModuleConstants.authType.basic) {
63
+ // could also confirm authCallbackParams against the auth requirements
64
+ authCallbackParams = mocks.authorizeParams
65
+ describe('getAuthorizationRequirements() test', () => {
66
+ it('should return auth requirements', async () => {
67
+ requirements = module.getAuthorizationRequirements();
68
+ expect(requirements).toBeDefined();
69
+ expect(requirements.type).toEqual(ModuleConstants.authType.basic);
70
+ });
71
+ });
72
+ } else if (definition.API.requesterType === ModuleConstants.authType.apiKey) {
73
+ // could also confirm authCallbackParams against the auth requirements
74
+ authCallbackParams = mocks.authorizeParams
75
+ describe('getAuthorizationRequirements() test', () => {
76
+ it('should return auth requirements', async () => {
77
+ requirements = module.getAuthorizationRequirements();
78
+ expect(requirements).toBeDefined();
79
+ expect(requirements.type).toEqual(ModuleConstants.authType.apiKey);
80
+ });
81
+ });
82
+ }
83
+
84
+ describe('Authorization requests', () => {
85
+ let firstRes;
86
+ it('processAuthorizationCallback()', async () => {
87
+ firstRes = await module.processAuthorizationCallback(authCallbackParams);
88
+ expect(firstRes).toBeDefined();
89
+ expect(firstRes.entity_id).toBeDefined();
90
+ expect(firstRes.credential_id).toBeDefined();
91
+ });
92
+ it('retrieves existing entity on subsequent calls', async () => {
93
+ const res = await module.processAuthorizationCallback(authCallbackParams);
94
+ expect(res).toEqual(firstRes);
95
+ });
96
+ });
97
+
98
+ describe('Test credential retrieval and module instantiation', () => {
99
+ it('retrieve by entity id', async () => {
100
+ const newModule = await getModule({
101
+ userId: module.userId,
102
+ entityId: module.entity.id
103
+ });
104
+ expect(newModule).toBeDefined();
105
+ expect(newModule.entity).toBeDefined();
106
+ expect(newModule.credential).toBeDefined();
107
+ expect(await newModule.testAuth()).toBeTruthy();
108
+
109
+ });
110
+
111
+ it('retrieve by credential id', async () => {
112
+ const newModule = await getModule({
113
+ userId: module.userId,
114
+ credentialId: module.credential.id
115
+ });
116
+ expect(newModule).toBeDefined();
117
+ expect(newModule.credential).toBeDefined();
118
+ expect(await newModule.testAuth()).toBeTruthy();
119
+ });
120
+ });
121
+ });
122
+ }
123
+
124
+ module.exports = { testAutherDefinition }
125
+
package/test/index.js CHANGED
@@ -1,9 +1,11 @@
1
- const { testDefinitionRequiredAuthMethods } = require('./auther-definition-method-tester');
2
- const { createMockIntegration, createMockApiObject } = require('./mock-integration');
1
+ const {testDefinitionRequiredAuthMethods} = require('./auther-definition-method-tester');
2
+ const {createMockIntegration, createMockApiObject} = require('./mock-integration');
3
+ const { testAutherDefinition } = require('./auther-definition-tester');
3
4
 
4
5
 
5
6
  module.exports = {
6
7
  createMockIntegration,
7
8
  createMockApiObject,
8
9
  testDefinitionRequiredAuthMethods,
10
+ testAutherDefinition,
9
11
  };
@@ -1,4 +1,8 @@
1
1
  const {
2
+ Auther,
3
+ Credential,
4
+ Entity,
5
+ IntegrationFactory,
2
6
  createObjectId,
3
7
  } = require('@friggframework/core');
4
8
 
@@ -7,6 +11,7 @@ async function createMockIntegration(
7
11
  userId = null,
8
12
  config = { type: IntegrationClass.Definition.name }
9
13
  ) {
14
+ const integrationFactory = new IntegrationFactory([IntegrationClass]);
10
15
  userId = userId || createObjectId();
11
16
 
12
17
  const insertOptions = {
@@ -19,8 +24,10 @@ async function createMockIntegration(
19
24
  const entities = [];
20
25
  for (const moduleName in IntegrationClass.modules) {
21
26
  const ModuleDef = IntegrationClass.Definition.modules[moduleName];
22
- // todo: create module using the new architecture
23
- const module = {}
27
+ const module = await Auther.getInstance({
28
+ definition: ModuleDef,
29
+ userId: userId,
30
+ });
24
31
  const credential = await module.CredentialModel.findOneAndUpdate(
25
32
  user,
26
33
  { $set: user },
@@ -44,8 +51,11 @@ async function createMockIntegration(
44
51
  );
45
52
  }
46
53
 
47
- // todo: create integration using the new architecture
48
- const integration = {}
54
+ const integration = await integrationFactory.createIntegration(
55
+ entities,
56
+ userId,
57
+ config
58
+ );
49
59
 
50
60
  integration.id = integration.record._id;
51
61