configurapi-runner-lambda-api 1.0.12 → 1.2.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,6 +1,6 @@
1
1
  {
2
2
  "name": "configurapi-runner-lambda-api",
3
- "version": "1.0.12",
3
+ "version": "1.2.0",
4
4
  "description": "A lambda runner for configurapi.",
5
5
  "bin": {
6
6
  "configurapi-runner-lambda-api": "src/index.js"
@@ -11,30 +11,36 @@ module.exports = {
11
11
  context.callbackWaitsForEmptyEventLoop = response.headers[awsCallbackWaitsForEmptyEventLoop];
12
12
  }
13
13
 
14
- let body = response.body;
14
+ if(response.body instanceof Buffer)
15
+ {
16
+ body = response.body.toString('base64');
17
+ }
18
+ else if(response.body instanceof String || typeof response.body === 'string')
19
+ {
20
+ body = response.body;
21
+ }
22
+ else if(response.body instanceof Object || typeof response.body === 'object')
23
+ {
24
+ let jsonReplacer = 'jsonReplacer' in response ? response.jsonReplacer : undefined;
15
25
 
16
- //Make JSON, if needed
17
- if(response.headers)
26
+ body = JSON.stringify(response.body, jsonReplacer);
27
+ }
28
+ else if(response.body instanceof Number || typeof response.body === 'number')
18
29
  {
19
- for(let headerKey of Object.keys(response.headers))
20
- {
21
- if(headerKey.toLowerCase() === 'content-type')
22
- {
23
- let contentType = response.headers[headerKey];
24
- if(contentType.includes('application/json'))
25
- {
26
- body = JSON.stringify(body);
27
- }
28
- }
29
- }
30
+ body = response.body + '';
31
+ }
32
+ else
33
+ {
34
+ body = response.body;
30
35
  }
36
+
31
37
  if (context.elbProvider) {
32
38
  return {
33
39
  statusCode: response.statusCode,
34
40
  headers: response.headers,
35
41
  body: body,
36
42
  statusDescription: `${response.statusCode} ${status[response.statusCode]}`,
37
- isBase64Encoded: false,
43
+ isBase64Encoded: response.body instanceof Buffer,
38
44
  multiValueHeaders: Object.keys(response.headers).reduce((memo, k) => {
39
45
  memo[k] = [response.headers[k]];
40
46
  return memo;
@@ -44,7 +50,8 @@ module.exports = {
44
50
  return {
45
51
  statusCode: response.statusCode,
46
52
  headers: response.headers,
47
- body: body
53
+ body: body,
54
+ isBase64Encoded: response.body instanceof Buffer
48
55
  };
49
56
  },
50
57
 
package/src/index.js CHANGED
@@ -7,8 +7,10 @@ const Adapter = require('./LambdaApiAdapter');
7
7
  ///////////////////////////////////
8
8
  function log(prefix, str)
9
9
  {
10
+ if(process.env.LOG_LEVEL==='none') return;
11
+
10
12
  let time = new Date().toISOString();
11
- console.debug(`${time} ${prefix}: ${oneliner(str)}`); //Use console.debug to exclude "$date $awsRequestId" prefix in CloudWatch logs
13
+ process.stdout.write(`${time} ${prefix}: ${oneliner(str)}\n`); //Use process.stdout.write() to exclude "$date $awsRequestId" prefix in CloudWatch logs
12
14
  }
13
15
 
14
16
 
@@ -42,7 +44,7 @@ exports.handler = async (awsEvent, context, callback) =>
42
44
 
43
45
  console.log = (message) => logWithEvent('Trace', event, message);
44
46
  console.error = (message) => logWithEvent('Error', event, message);
45
- console.warn = console.log;
47
+ console.warn = (message) => logWithEvent('Warn', event, message);
46
48
 
47
49
  await service.process(event);
48
50