idea-aws 3.13.4 → 3.13.7

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,7 @@ import { GenericController, GenericControllerOptions } from './genericController
9
9
  export declare abstract class ResourceController extends GenericController {
10
10
  protected event: APIGatewayProxyEventV2 | APIGatewayProxyEvent;
11
11
  protected callback: Callback;
12
+ protected initError: boolean;
12
13
  protected authorization: string;
13
14
  protected claims: any;
14
15
  protected principalId: string;
@@ -31,6 +32,10 @@ export declare abstract class ResourceController extends GenericController {
31
32
  constructor(event: APIGatewayProxyEventV2 | APIGatewayProxyEvent, callback: Callback, options?: ResourceControllerOptions);
32
33
  private initFromEventV2;
33
34
  private initFromEventV1;
35
+ /**
36
+ * Force the parsing of a query parameter as an array of strings.
37
+ */
38
+ protected getQueryParamAsArray(paramName: string): string[];
34
39
  handleRequest: () => Promise<void>;
35
40
  private controlHandlerError;
36
41
  protected done(err: any, res?: any, statusCode?: number): void;
@@ -13,12 +13,15 @@ const genericController_1 = require("./genericController");
13
13
  class ResourceController extends genericController_1.GenericController {
14
14
  constructor(event, callback, options = {}) {
15
15
  super(event, callback, options);
16
+ this.initError = false;
16
17
  this.logger = new logger_1.Logger();
17
18
  this.templateMatcher = /{{\s?([^{}\s]*)\s?}}/g;
18
19
  ///
19
20
  /// REQUEST HANDLERS
20
21
  ///
21
22
  this.handleRequest = async () => {
23
+ if (this.initError)
24
+ return;
22
25
  try {
23
26
  await this.checkAuthBeforeRequest();
24
27
  try {
@@ -85,24 +88,30 @@ class ResourceController extends genericController_1.GenericController {
85
88
  };
86
89
  this.event = event;
87
90
  this.callback = callback;
88
- if (event.version === '2.0')
89
- this.initFromEventV2(event, options);
90
- else
91
- this.initFromEventV1(event, options);
92
- this.logRequestsWithKey = options.logRequestsWithKey;
93
- // acquire some info about the client, if available
94
- let version = '?', platform = '?';
95
- if (this.queryParams['_v']) {
96
- version = this.queryParams['_v'];
97
- delete this.queryParams['_v'];
91
+ try {
92
+ if (event.version === '2.0')
93
+ this.initFromEventV2(event, options);
94
+ else
95
+ this.initFromEventV1(event, options);
96
+ this.logRequestsWithKey = options.logRequestsWithKey;
97
+ // acquire some info about the client, if available
98
+ let version = '?', platform = '?';
99
+ if (this.queryParams['_v']) {
100
+ version = this.queryParams['_v'];
101
+ delete this.queryParams['_v'];
102
+ }
103
+ if (this.queryParams['_p']) {
104
+ platform = this.queryParams['_p'];
105
+ delete this.queryParams['_p'];
106
+ }
107
+ // print the initial log
108
+ const info = { principalId: this.principalId, queryParams: this.queryParams, body: this.body, version, platform };
109
+ this.logger.info(`START: ${this.httpMethod} ${this.path}`, info);
98
110
  }
99
- if (this.queryParams['_p']) {
100
- platform = this.queryParams['_p'];
101
- delete this.queryParams['_p'];
111
+ catch (err) {
112
+ this.initError = true;
113
+ this.done(this.controlHandlerError(err, 'INIT-ERROR', 'Malformed request'));
102
114
  }
103
- // print the initial log
104
- const info = { principalId: this.principalId, queryParams: this.queryParams, body: this.body, version, platform };
105
- this.logger.info(`START: ${this.httpMethod} ${this.path}`, info);
106
115
  }
107
116
  initFromEventV2(event, options) {
108
117
  this.authorization = event.headers.authorization;
@@ -119,7 +128,12 @@ class ResourceController extends genericController_1.GenericController {
119
128
  this.pathParameters[param] = event.pathParameters[param] ? decodeURIComponent(event.pathParameters[param]) : null;
120
129
  this.resourceId = this.pathParameters[options.resourceId || 'proxy'];
121
130
  this.queryParams = event.queryStringParameters || {};
122
- this.body = (event.body ? JSON.parse(event.body) : {}) || {};
131
+ try {
132
+ this.body = (event.body ? JSON.parse(event.body) : {}) || {};
133
+ }
134
+ catch (error) {
135
+ throw new RCError('Malformed body');
136
+ }
123
137
  }
124
138
  initFromEventV1(event, options) {
125
139
  this.authorization = event.headers.Authorization;
@@ -135,7 +149,23 @@ class ResourceController extends genericController_1.GenericController {
135
149
  this.pathParameters[param] = event.pathParameters[param] ? decodeURIComponent(event.pathParameters[param]) : null;
136
150
  this.resourceId = this.pathParameters[options.resourceId || 'proxy'];
137
151
  this.queryParams = event.queryStringParameters || {};
138
- this.body = (event.body ? JSON.parse(event.body) : {}) || {};
152
+ try {
153
+ this.body = (event.body ? JSON.parse(event.body) : {}) || {};
154
+ }
155
+ catch (error) {
156
+ throw new RCError('Malformed body');
157
+ }
158
+ }
159
+ /**
160
+ * Force the parsing of a query parameter as an array of strings.
161
+ */
162
+ getQueryParamAsArray(paramName) {
163
+ if (!this.queryParams[paramName])
164
+ return [];
165
+ else if (Array.isArray(this.queryParams[paramName]))
166
+ return this.queryParams[paramName];
167
+ else
168
+ return String(this.queryParams[paramName]).split(',');
139
169
  }
140
170
  controlHandlerError(err = {}, context, replaceWithErrorMessage) {
141
171
  if (err instanceof RCError)
package/dist/src/s3.js CHANGED
@@ -72,7 +72,7 @@ class S3 {
72
72
  * Get an object from a S3 bucket.
73
73
  */
74
74
  async getObject(options) {
75
- logger.debug(`S3 get object: ${options.type}`);
75
+ logger.debug(`S3 get object: ${options.key}`);
76
76
  const result = await this.s3.getObject({ Bucket: options.bucket, Key: options.key }).promise();
77
77
  switch (options.type) {
78
78
  case GetObjectTypes.JSON:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.13.4",
3
+ "version": "3.13.7",
4
4
  "description": "AWS wrappers to use in IDEA's back-ends",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",