@friggframework/core 2.0.0--canary.726.131e2b3.0 → 2.0.0--canary.727.f8fcc58.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.
@@ -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 = err.isBoom ? err : Boom.boomify(err);
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.loadDynamicUserActions();
561
- const filteredDynamicActions = actionType
562
- ? Object.fromEntries(
563
- Object.entries(dynamicUserActions).filter(
564
- ([_, event]) => event.userActionType === actionType
565
- )
566
- )
567
- : dynamicUserActions;
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 = await this.loadDynamicUserActions();
863
+ const additionalUserActions =
864
+ await this._loadDynamicUserActionEvents();
851
865
  this.events = { ...this.events, ...additionalUserActions };
852
866
  } catch (e) {
853
867
  this.addError(e);
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--canary.726.131e2b3.0",
4
+ "version": "2.0.0--canary.727.f8fcc58.0",
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--canary.726.131e2b3.0",
14
+ "@friggframework/schemas": "2.0.0--canary.727.f8fcc58.0",
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--canary.726.131e2b3.0",
53
- "@friggframework/prettier-config": "2.0.0--canary.726.131e2b3.0",
54
- "@friggframework/test": "2.0.0--canary.726.131e2b3.0",
52
+ "@friggframework/eslint-config": "2.0.0--canary.727.f8fcc58.0",
53
+ "@friggframework/prettier-config": "2.0.0--canary.727.f8fcc58.0",
54
+ "@friggframework/test": "2.0.0--canary.727.f8fcc58.0",
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": "131e2b30f186de52170e32a5fa6948e568445593"
95
+ "gitHead": "f8fcc5824935a85a95c9997bc52ca1c6e973b91c"
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
- return JSON.parse(tokenStr);
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
- return JSON.parse(tokenStr);
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
- return JSON.parse(tokenStr);
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