serverless-offline 13.6.0 → 14.1.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.
@@ -0,0 +1,57 @@
1
+ /* eslint-disable prefer-rest-params */
2
+ /* eslint-disable func-names */
3
+ /**
4
+ * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ */
6
+
7
+ "use strict"
8
+
9
+ const process = require("node:process")
10
+
11
+ const EnvVarName = "AWS_LAMBDA_RUNTIME_VERBOSE"
12
+ const Tag = "RUNTIME"
13
+ const Verbosity = (() => {
14
+ if (!process.env[EnvVarName]) {
15
+ return 0
16
+ }
17
+
18
+ try {
19
+ const verbosity = Number.parseInt(process.env[EnvVarName], 10)
20
+ // eslint-disable-next-line unicorn/no-nested-ternary
21
+ return verbosity < 0 ? 0 : verbosity > 3 ? 3 : verbosity
22
+ } catch {
23
+ return 0
24
+ }
25
+ })()
26
+
27
+ exports.logger = function (category) {
28
+ return {
29
+ verbose() {
30
+ if (Verbosity >= 1) {
31
+ const args = [...arguments].map((arg) =>
32
+ typeof arg === "function" ? arg() : arg,
33
+ )
34
+ // eslint-disable-next-line no-console
35
+ Reflect.apply(console.log, null, [Tag, category, ...args])
36
+ }
37
+ },
38
+ vverbose() {
39
+ if (Verbosity >= 2) {
40
+ const args = [...arguments].map((arg) =>
41
+ typeof arg === "function" ? arg() : arg,
42
+ )
43
+ // eslint-disable-next-line no-console
44
+ Reflect.apply(console.log, null, [Tag, category, ...args])
45
+ }
46
+ },
47
+ vvverbose() {
48
+ if (Verbosity >= 3) {
49
+ const args = [...arguments].map((arg) =>
50
+ typeof arg === "function" ? arg() : arg,
51
+ )
52
+ // eslint-disable-next-line no-console
53
+ Reflect.apply(console.log, null, [Tag, category, ...args])
54
+ }
55
+ },
56
+ }
57
+ }
@@ -1,6 +1,7 @@
1
1
  # copy/pasted entirely as is from:
2
2
  # https://github.com/serverless/serverless/blob/v1.50.0/lib/plugins/aws/invokeLocal/invoke.py
3
3
 
4
+ import base64
4
5
  import subprocess
5
6
  import argparse
6
7
  import json
@@ -10,6 +11,7 @@ import os
10
11
  from time import strftime, time
11
12
  from importlib import import_module
12
13
 
14
+
13
15
  class FakeLambdaContext(object):
14
16
  def __init__(self, name='Fake', version='LATEST', timeout=6, **kwargs):
15
17
  self.name = name
@@ -102,5 +104,9 @@ if __name__ == '__main__':
102
104
  '__offline_payload__': result
103
105
  }
104
106
 
107
+ if isinstance(result['body'], bytes):
108
+ data['__offline_payload__']['body'] = base64.b64encode(result['body']).decode('utf-8')
109
+ data['isBase64Encoded'] = True
110
+
105
111
  sys.stdout.write(json.dumps(data))
106
112
  sys.stdout.write('\n')