@friggframework/core 2.0.0-next.124 → 2.0.0-next.126
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/handlers/app-handler-helpers.js +12 -1
- package/integrations/integration-base.js +23 -9
- package/integrations/integration-router.js +12 -0
- package/integrations/use-cases/delete-integration-for-user.js +8 -11
- package/integrations/use-cases/get-integration-instance.js +12 -12
- package/integrations/use-cases/update-integration.js +12 -12
- package/package.json +6 -6
- package/token/repositories/token-repository-documentdb.js +13 -1
- package/token/repositories/token-repository-mongo.js +13 -1
- package/token/repositories/token-repository-postgres.js +13 -1
|
@@ -9,6 +9,17 @@ const serverlessHttp = require('serverless-http');
|
|
|
9
9
|
|
|
10
10
|
const log = getLogger('frigg.http');
|
|
11
11
|
|
|
12
|
+
const isHttpErrorStatus = (statusCode) =>
|
|
13
|
+
Number.isInteger(statusCode) && statusCode >= 400 && statusCode <= 599;
|
|
14
|
+
|
|
15
|
+
const toBoom = (err) => {
|
|
16
|
+
if (err.isBoom) return err;
|
|
17
|
+
if (err.isClientSafe === true && isHttpErrorStatus(err.statusCode)) {
|
|
18
|
+
return Boom.boomify(err, { statusCode: err.statusCode });
|
|
19
|
+
}
|
|
20
|
+
return Boom.boomify(err);
|
|
21
|
+
};
|
|
22
|
+
|
|
12
23
|
const createApp = (applyMiddleware) => {
|
|
13
24
|
const app = express();
|
|
14
25
|
|
|
@@ -27,7 +38,7 @@ const createApp = (applyMiddleware) => {
|
|
|
27
38
|
|
|
28
39
|
// The express boundary: send the error response and log it one time.
|
|
29
40
|
app.use((err, req, res, next) => {
|
|
30
|
-
const boomError =
|
|
41
|
+
const boomError = toBoom(err);
|
|
31
42
|
const {
|
|
32
43
|
output: { statusCode = 500 },
|
|
33
44
|
} = boomError;
|
|
@@ -557,17 +557,30 @@ class IntegrationBase {
|
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
|
-
const dynamicUserActions = await this.
|
|
561
|
-
const filteredDynamicActions =
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
560
|
+
const dynamicUserActions = await this._loadDynamicUserActionEvents();
|
|
561
|
+
const filteredDynamicActions = Object.fromEntries(
|
|
562
|
+
Object.entries(dynamicUserActions).filter(
|
|
563
|
+
([_, event]) =>
|
|
564
|
+
event.type === constantsToBeMigrated.types.USER_ACTION &&
|
|
565
|
+
(!actionType || event.userActionType === actionType)
|
|
566
|
+
)
|
|
567
|
+
);
|
|
568
568
|
return { ...userActions, ...filteredDynamicActions };
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
async _loadDynamicUserActionEvents() {
|
|
572
|
+
const dynamicUserActions = await this.loadDynamicUserActions();
|
|
573
|
+
return Object.fromEntries(
|
|
574
|
+
Object.entries(dynamicUserActions).map(([key, event]) => [
|
|
575
|
+
key,
|
|
576
|
+
{
|
|
577
|
+
...event,
|
|
578
|
+
type: event.type ?? constantsToBeMigrated.types.USER_ACTION,
|
|
579
|
+
},
|
|
580
|
+
])
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
571
584
|
async getActionOptions(actionId, data) {
|
|
572
585
|
const options = {
|
|
573
586
|
jsonSchema: {},
|
|
@@ -847,7 +860,8 @@ class IntegrationBase {
|
|
|
847
860
|
|
|
848
861
|
async initialize() {
|
|
849
862
|
try {
|
|
850
|
-
const additionalUserActions =
|
|
863
|
+
const additionalUserActions =
|
|
864
|
+
await this._loadDynamicUserActionEvents();
|
|
851
865
|
this.events = { ...this.events, ...additionalUserActions };
|
|
852
866
|
} catch (e) {
|
|
853
867
|
this.addError(e);
|
|
@@ -257,6 +257,15 @@ function checkRequiredParams(params, requiredKeys) {
|
|
|
257
257
|
return returnDict;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
function assertUserAction(integration, actionId) {
|
|
261
|
+
if (
|
|
262
|
+
!Object.hasOwn(integration.events, actionId) ||
|
|
263
|
+
integration.events[actionId].type !== 'USER_ACTION'
|
|
264
|
+
) {
|
|
265
|
+
throw Boom.notFound(`User action ${actionId} does not exist`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
260
269
|
/**
|
|
261
270
|
* Sets up integration-related routes on the provided Express router
|
|
262
271
|
* @param {express.Router} router - Express router instance to add routes to
|
|
@@ -393,6 +402,7 @@ function setIntegrationRoutes(router, authenticateUser, useCases) {
|
|
|
393
402
|
params.integrationId,
|
|
394
403
|
user.getId()
|
|
395
404
|
);
|
|
405
|
+
assertUserAction(integration, params.actionId);
|
|
396
406
|
|
|
397
407
|
res.json(
|
|
398
408
|
await integration.send('GET_USER_ACTION_OPTIONS', {
|
|
@@ -418,6 +428,7 @@ function setIntegrationRoutes(router, authenticateUser, useCases) {
|
|
|
418
428
|
params.integrationId,
|
|
419
429
|
user.getId()
|
|
420
430
|
);
|
|
431
|
+
assertUserAction(integration, params.actionId);
|
|
421
432
|
|
|
422
433
|
res.json(
|
|
423
434
|
await integration.send('REFRESH_USER_ACTION_OPTIONS', {
|
|
@@ -439,6 +450,7 @@ function setIntegrationRoutes(router, authenticateUser, useCases) {
|
|
|
439
450
|
params.integrationId,
|
|
440
451
|
user.getId()
|
|
441
452
|
);
|
|
453
|
+
assertUserAction(integration, params.actionId);
|
|
442
454
|
res.json(await integration.send(params.actionId, req.body));
|
|
443
455
|
})
|
|
444
456
|
);
|
|
@@ -31,14 +31,17 @@ class DeleteIntegrationForUser {
|
|
|
31
31
|
* @param {string} integrationId - ID of the integration to delete.
|
|
32
32
|
* @param {string} userId - ID of the user requesting the deletion.
|
|
33
33
|
* @returns {Promise<void>} Resolves when the integration is successfully deleted.
|
|
34
|
-
* @throws {Boom.notFound} When integration
|
|
35
|
-
* @throws {Error} When the integration doesn't belong to the specified user.
|
|
34
|
+
* @throws {Boom.notFound} When integration does not exist or doesn't belong to the specified user.
|
|
36
35
|
*/
|
|
37
36
|
async execute(integrationId, userId) {
|
|
38
|
-
const integrationRecord =
|
|
39
|
-
|
|
37
|
+
const integrationRecord = await this.integrationRepository
|
|
38
|
+
.findIntegrationById(integrationId)
|
|
39
|
+
.catch((error) => {
|
|
40
|
+
if (error.message?.includes('not found')) return null;
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
40
43
|
|
|
41
|
-
if (!integrationRecord) {
|
|
44
|
+
if (!integrationRecord || integrationRecord.userId !== userId) {
|
|
42
45
|
throw Boom.notFound(
|
|
43
46
|
`Integration with id of ${integrationId} does not exist`
|
|
44
47
|
);
|
|
@@ -50,12 +53,6 @@ class DeleteIntegrationForUser {
|
|
|
50
53
|
integrationRecord.config.type
|
|
51
54
|
);
|
|
52
55
|
|
|
53
|
-
if (integrationRecord.userId !== userId) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Integration ${integrationId} does not belong to User ${userId}`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
56
|
// Load modules with API clients for webhook deletion
|
|
60
57
|
const modules = [];
|
|
61
58
|
const failedModuleLoads = [];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const Boom = require('@hapi/boom');
|
|
1
2
|
// Removed Integration wrapper - using IntegrationBase directly
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -24,15 +25,20 @@ class GetIntegrationInstance {
|
|
|
24
25
|
* @param {string} integrationId - ID of the integration to retrieve.
|
|
25
26
|
* @param {string} userId - ID of the user requesting the integration.
|
|
26
27
|
* @returns {Promise<Integration>} The fully initialized integration instance.
|
|
27
|
-
* @throws {
|
|
28
|
+
* @throws {Boom.notFound} When integration is not found or doesn't belong to user.
|
|
29
|
+
* @throws {Error} When integration class is not found.
|
|
28
30
|
*/
|
|
29
31
|
async execute(integrationId, userId) {
|
|
30
|
-
const integrationRecord =
|
|
31
|
-
|
|
32
|
+
const integrationRecord = await this.integrationRepository
|
|
33
|
+
.findIntegrationById(integrationId)
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
if (error.message?.includes('not found')) return null;
|
|
36
|
+
throw error;
|
|
37
|
+
});
|
|
32
38
|
|
|
33
|
-
if (!integrationRecord) {
|
|
34
|
-
throw
|
|
35
|
-
`
|
|
39
|
+
if (!integrationRecord || integrationRecord.userId !== userId) {
|
|
40
|
+
throw Boom.notFound(
|
|
41
|
+
`Integration with id of ${integrationId} does not exist`
|
|
36
42
|
);
|
|
37
43
|
}
|
|
38
44
|
|
|
@@ -48,12 +54,6 @@ class GetIntegrationInstance {
|
|
|
48
54
|
);
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
if (integrationRecord.userId !== userId) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Integration ${integrationId} does not belong to User ${userId}`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
57
|
const modules = [];
|
|
58
58
|
for (const entityId of integrationRecord.entitiesIds) {
|
|
59
59
|
const moduleInstance = await this.moduleFactory.getModuleInstance(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const Boom = require('@hapi/boom');
|
|
1
2
|
const {
|
|
2
3
|
mapIntegrationClassToIntegrationDTO,
|
|
3
4
|
} = require('../utils/map-integration-dto');
|
|
@@ -27,16 +28,21 @@ class UpdateIntegration {
|
|
|
27
28
|
* @param {string} userId - ID of the user requesting the update.
|
|
28
29
|
* @param {Object} config - New configuration object for the integration.
|
|
29
30
|
* @returns {Promise<Object>} The updated integration DTO.
|
|
30
|
-
* @throws {
|
|
31
|
+
* @throws {Boom.notFound} When integration is not found or doesn't belong to user.
|
|
32
|
+
* @throws {Error} When integration class is not found.
|
|
31
33
|
*/
|
|
32
34
|
async execute(integrationId, userId, config) {
|
|
33
35
|
// 1. Get integration record from repository
|
|
34
|
-
const integrationRecord =
|
|
35
|
-
|
|
36
|
+
const integrationRecord = await this.integrationRepository
|
|
37
|
+
.findIntegrationById(integrationId)
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
if (error.message?.includes('not found')) return null;
|
|
40
|
+
throw error;
|
|
41
|
+
});
|
|
36
42
|
|
|
37
|
-
if (!integrationRecord) {
|
|
38
|
-
throw
|
|
39
|
-
`
|
|
43
|
+
if (!integrationRecord || integrationRecord.userId !== userId) {
|
|
44
|
+
throw Boom.notFound(
|
|
45
|
+
`Integration with id of ${integrationId} does not exist`
|
|
40
46
|
);
|
|
41
47
|
}
|
|
42
48
|
|
|
@@ -53,12 +59,6 @@ class UpdateIntegration {
|
|
|
53
59
|
);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
if (integrationRecord.userId !== userId) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
`Integration ${integrationId} does not belong to User ${userId}`
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
62
|
// 3. Load modules based on entity references
|
|
63
63
|
const modules = [];
|
|
64
64
|
for (const entityId of integrationRecord.entitiesIds) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.126",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"@aws-sdk/client-sqs": "^3.588.0",
|
|
12
12
|
"@aws-sdk/client-ssm": "^3.588.0",
|
|
13
13
|
"@aws-sdk/s3-request-presigner": "^3.588.0",
|
|
14
|
-
"@friggframework/schemas": "2.0.0-next.
|
|
14
|
+
"@friggframework/schemas": "2.0.0-next.126",
|
|
15
15
|
"@hapi/boom": "^10.0.1",
|
|
16
16
|
"@opentelemetry/api": "^1.9.1",
|
|
17
17
|
"@opentelemetry/context-async-hooks": "^2.9.0",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@friggframework/eslint-config": "2.0.0-next.
|
|
53
|
-
"@friggframework/prettier-config": "2.0.0-next.
|
|
54
|
-
"@friggframework/test": "2.0.0-next.
|
|
52
|
+
"@friggframework/eslint-config": "2.0.0-next.126",
|
|
53
|
+
"@friggframework/prettier-config": "2.0.0-next.126",
|
|
54
|
+
"@friggframework/test": "2.0.0-next.126",
|
|
55
55
|
"@prisma/client": "^6.19.3",
|
|
56
56
|
"@types/lodash": "4.17.15",
|
|
57
57
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "be8690d56e4e772fc744f414a7e3bed7363ad9b5"
|
|
96
96
|
}
|
|
@@ -119,7 +119,19 @@ class TokenRepositoryDocumentDB extends TokenRepositoryInterface {
|
|
|
119
119
|
|
|
120
120
|
getJSONTokenFromBase64BufferToken(buffer) {
|
|
121
121
|
const tokenStr = Buffer.from(buffer.trim(), 'base64').toString('ascii');
|
|
122
|
-
|
|
122
|
+
let jsonToken;
|
|
123
|
+
try {
|
|
124
|
+
jsonToken = JSON.parse(tokenStr);
|
|
125
|
+
} catch {
|
|
126
|
+
jsonToken = null;
|
|
127
|
+
}
|
|
128
|
+
if (
|
|
129
|
+
!['string', 'number'].includes(typeof jsonToken?.id) ||
|
|
130
|
+
typeof jsonToken?.token !== 'string'
|
|
131
|
+
) {
|
|
132
|
+
throw new ClientSafeError('Invalid Token: Token is malformed', 401);
|
|
133
|
+
}
|
|
134
|
+
return jsonToken;
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
_mapToken(record) {
|
|
@@ -212,7 +212,19 @@ class TokenRepositoryMongo extends TokenRepositoryInterface {
|
|
|
212
212
|
*/
|
|
213
213
|
getJSONTokenFromBase64BufferToken(buffer) {
|
|
214
214
|
const tokenStr = Buffer.from(buffer.trim(), 'base64').toString('ascii');
|
|
215
|
-
|
|
215
|
+
let jsonToken;
|
|
216
|
+
try {
|
|
217
|
+
jsonToken = JSON.parse(tokenStr);
|
|
218
|
+
} catch {
|
|
219
|
+
jsonToken = null;
|
|
220
|
+
}
|
|
221
|
+
if (
|
|
222
|
+
!['string', 'number'].includes(typeof jsonToken?.id) ||
|
|
223
|
+
typeof jsonToken?.token !== 'string'
|
|
224
|
+
) {
|
|
225
|
+
throw new ClientSafeError('Invalid Token: Token is malformed', 401);
|
|
226
|
+
}
|
|
227
|
+
return jsonToken;
|
|
216
228
|
}
|
|
217
229
|
}
|
|
218
230
|
|
|
@@ -257,7 +257,19 @@ class TokenRepositoryPostgres extends TokenRepositoryInterface {
|
|
|
257
257
|
*/
|
|
258
258
|
getJSONTokenFromBase64BufferToken(buffer) {
|
|
259
259
|
const tokenStr = Buffer.from(buffer.trim(), 'base64').toString('ascii');
|
|
260
|
-
|
|
260
|
+
let jsonToken;
|
|
261
|
+
try {
|
|
262
|
+
jsonToken = JSON.parse(tokenStr);
|
|
263
|
+
} catch {
|
|
264
|
+
jsonToken = null;
|
|
265
|
+
}
|
|
266
|
+
if (
|
|
267
|
+
!['string', 'number'].includes(typeof jsonToken?.id) ||
|
|
268
|
+
typeof jsonToken?.token !== 'string'
|
|
269
|
+
) {
|
|
270
|
+
throw new ClientSafeError('Invalid Token: Token is malformed', 401);
|
|
271
|
+
}
|
|
272
|
+
return jsonToken;
|
|
261
273
|
}
|
|
262
274
|
}
|
|
263
275
|
|