serverless-http-invoker 1.0.14 → 2.0.0-beta.1
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/.github/dependabot.yml +2 -3
- package/.github/workflows/build.yml +20 -84
- package/examples/basic/basic.spec.js +6 -6
- package/examples/basic/handler.js +4 -4
- package/examples/basic/serverless.yml +1 -1
- package/examples/comprehensive/comprehensive.spec.js +36 -36
- package/examples/comprehensive/handler.js +19 -19
- package/examples/comprehensive/serverless.yml +1 -1
- package/index.js +21 -22
- package/package.json +7 -7
- package/release.config.js +2 -2
- package/.github/workflows/dependabot-validate.yml +0 -19
package/.github/dependabot.yml
CHANGED
|
@@ -2,13 +2,12 @@ version: 2
|
|
|
2
2
|
updates:
|
|
3
3
|
# docs v2 https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
4
4
|
- package-ecosystem: "npm"
|
|
5
|
+
directory: "/"
|
|
5
6
|
schedule:
|
|
6
7
|
interval: "monthly"
|
|
7
|
-
|
|
8
|
-
day: "saturday"
|
|
8
|
+
day: "friday"
|
|
9
9
|
allow:
|
|
10
10
|
- dependency-type: "direct"
|
|
11
|
-
directory: "/"
|
|
12
11
|
commit-message:
|
|
13
12
|
# for production deps, prefix commit messages with "fix" (trigger a patch release)
|
|
14
13
|
prefix: "fix"
|
|
@@ -1,89 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# We want pushes to main, beta, and alpha to trigger a publish to npm for the corresponding npm dist-tag.
|
|
2
|
+
# Any pull request targeting deploy branches should run all tests.
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
-
branches: [main]
|
|
5
|
+
branches: [main, beta, alpha]
|
|
6
|
+
|
|
6
7
|
pull_request:
|
|
7
|
-
branches: [main]
|
|
8
|
+
branches: [main, beta, alpha]
|
|
8
9
|
|
|
9
10
|
jobs:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
run: |
|
|
26
|
-
npm run lint
|
|
27
|
-
|
|
28
|
-
build_and_test:
|
|
29
|
-
runs-on: ubuntu-20.04
|
|
30
|
-
strategy:
|
|
31
|
-
matrix:
|
|
32
|
-
node: [10, 12, 14]
|
|
33
|
-
|
|
34
|
-
steps:
|
|
35
|
-
- uses: actions/checkout@v2
|
|
36
|
-
- name: Use Node.js ${{ matrix.node }}
|
|
37
|
-
uses: actions/setup-node@v2
|
|
38
|
-
with:
|
|
39
|
-
node-version: ${{ matrix.node }}
|
|
40
|
-
|
|
41
|
-
- name: install dependencies
|
|
42
|
-
run: |
|
|
43
|
-
npm i
|
|
44
|
-
|
|
45
|
-
- name: test
|
|
46
|
-
env:
|
|
47
|
-
CI_NODE_VERSION: ${{ matrix.node }}
|
|
48
|
-
run: |
|
|
49
|
-
npm run test
|
|
50
|
-
|
|
51
|
-
- name: publish coverage
|
|
52
|
-
uses: coverallsapp/github-action@master
|
|
53
|
-
continue-on-error: true
|
|
54
|
-
with:
|
|
55
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
56
|
-
flag-name: nodejs-${{ matrix.node }}
|
|
57
|
-
parallel: true
|
|
58
|
-
|
|
59
|
-
finish_tests:
|
|
60
|
-
needs: build_and_test
|
|
61
|
-
runs-on: ubuntu-20.04
|
|
62
|
-
steps:
|
|
63
|
-
- name: Coveralls Finished
|
|
64
|
-
uses: coverallsapp/github-action@master
|
|
65
|
-
continue-on-error: true
|
|
66
|
-
with:
|
|
67
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
68
|
-
parallel-finished: true
|
|
69
|
-
|
|
70
|
-
deploy_package:
|
|
71
|
-
needs: finish_tests
|
|
72
|
-
runs-on: ubuntu-20.04
|
|
73
|
-
steps:
|
|
74
|
-
- uses: actions/checkout@v2
|
|
75
|
-
|
|
76
|
-
- name: Use Node.js v12.x
|
|
77
|
-
uses: actions/setup-node@v1
|
|
78
|
-
with:
|
|
79
|
-
node-version: v12.x
|
|
80
|
-
|
|
81
|
-
#- name: debug deploy_package
|
|
82
|
-
# uses: actions/bin/debug@master
|
|
83
|
-
|
|
84
|
-
- name: deploy via semantic-release
|
|
85
|
-
env:
|
|
86
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
87
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
88
|
-
run: |
|
|
89
|
-
npx semantic-release@17
|
|
11
|
+
test:
|
|
12
|
+
uses: activescott/github-actions-workflows/.github/workflows/npm-tester.yml@npm-tester-v4
|
|
13
|
+
with:
|
|
14
|
+
package_dir: ./
|
|
15
|
+
node_versions: "[14, 16, 18]"
|
|
16
|
+
do_coveralls: true
|
|
17
|
+
|
|
18
|
+
publish:
|
|
19
|
+
if: ${{ github.event_name != 'pull_request' }}
|
|
20
|
+
needs: [test]
|
|
21
|
+
uses: activescott/github-actions-workflows/.github/workflows/npm-publisher.yml@npm-publisher-v4.0.1
|
|
22
|
+
with:
|
|
23
|
+
package_dir: ./
|
|
24
|
+
secrets:
|
|
25
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -4,18 +4,18 @@ const path = require("path")
|
|
|
4
4
|
const expect = require("chai").expect
|
|
5
5
|
const ServerlessInvoker = require("../../index")
|
|
6
6
|
|
|
7
|
-
describe("basic", function() {
|
|
7
|
+
describe("basic", function () {
|
|
8
8
|
let sls = null
|
|
9
|
-
beforeEach(function() {
|
|
9
|
+
beforeEach(function () {
|
|
10
10
|
sls = new ServerlessInvoker(path.join(__dirname))
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
it("should invoke simple path", function() {
|
|
13
|
+
it("should invoke simple path", function () {
|
|
14
14
|
const response = sls.invoke("GET api/hello")
|
|
15
15
|
return expect(response).to.eventually.have.property("statusCode", 200)
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
it("should have event.httpMethod", function() {
|
|
18
|
+
it("should have event.httpMethod", function () {
|
|
19
19
|
const response = sls.invoke("GET api/hello")
|
|
20
20
|
return expect(response).to.eventually.have.deep.nested.property(
|
|
21
21
|
"body.input.httpMethod",
|
|
@@ -23,7 +23,7 @@ describe("basic", function() {
|
|
|
23
23
|
)
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
-
it("should have event.path", function() {
|
|
26
|
+
it("should have event.path", function () {
|
|
27
27
|
const response = sls.invoke("GET api/hello")
|
|
28
28
|
return expect(response).to.eventually.have.deep.nested.property(
|
|
29
29
|
"body.input.path",
|
|
@@ -31,7 +31,7 @@ describe("basic", function() {
|
|
|
31
31
|
)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
it("should have event.resource", function() {
|
|
34
|
+
it("should have event.resource", function () {
|
|
35
35
|
const response = sls.invoke("GET api/hello")
|
|
36
36
|
return expect(response).to.eventually.have.deep.nested.property(
|
|
37
37
|
"body.input.resource",
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
const assert = require("assert")
|
|
3
3
|
|
|
4
|
-
module.exports.hello = async event => {
|
|
4
|
+
module.exports.hello = async (event) => {
|
|
5
5
|
return {
|
|
6
6
|
statusCode: 200,
|
|
7
7
|
headers: {
|
|
8
|
-
"Content-Type": "application/json"
|
|
8
|
+
"Content-Type": "application/json",
|
|
9
9
|
},
|
|
10
10
|
body: JSON.stringify(
|
|
11
11
|
{
|
|
12
12
|
message: "Go Serverless v1.0! Your function executed successfully!",
|
|
13
|
-
input: event
|
|
13
|
+
input: event,
|
|
14
14
|
},
|
|
15
15
|
null,
|
|
16
16
|
2
|
|
17
|
-
)
|
|
17
|
+
),
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -6,32 +6,32 @@ const ServerlessInvoker = require("../../index")
|
|
|
6
6
|
|
|
7
7
|
let sls = null
|
|
8
8
|
|
|
9
|
-
beforeEach(function() {
|
|
9
|
+
beforeEach(function () {
|
|
10
10
|
process.chdir(path.join(__dirname))
|
|
11
11
|
sls = new ServerlessInvoker(path.join(__dirname))
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
it("should work with callbacks too", function() {
|
|
14
|
+
it("should work with callbacks too", function () {
|
|
15
15
|
const response = sls.invoke("GET api/callback")
|
|
16
16
|
return expect(response).to.eventually.have.property("statusCode", 200)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
it("should invoke path with params", function() {
|
|
19
|
+
it("should invoke path with params", function () {
|
|
20
20
|
const response = sls.invoke("GET api/hello/world")
|
|
21
21
|
return expect(response).to.eventually.have.property("statusCode", 200)
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
it("should invoke path with shorthand", function() {
|
|
24
|
+
it("should invoke path with shorthand", function () {
|
|
25
25
|
const response = sls.invoke("GET api/shorthand")
|
|
26
26
|
return expect(response).to.eventually.have.property("statusCode", 200)
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
it("should invoke path with multiple params", function() {
|
|
29
|
+
it("should invoke path with multiple params", function () {
|
|
30
30
|
const response = sls.invoke("GET api/res1/1111/res2/2222")
|
|
31
31
|
return expect(response).to.eventually.have.property("statusCode", 200)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
it("should parse json response body", function() {
|
|
34
|
+
it("should parse json response body", function () {
|
|
35
35
|
const response = sls.invoke("GET api/hello")
|
|
36
36
|
expect(response).to.eventually.have.property("statusCode", 200)
|
|
37
37
|
return expect(response).to.eventually.have.deep.nested.property(
|
|
@@ -40,7 +40,7 @@ it("should parse json response body", function() {
|
|
|
40
40
|
)
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
it("should load environment", function() {
|
|
43
|
+
it("should load environment", function () {
|
|
44
44
|
const response = sls.invoke("GET api/env")
|
|
45
45
|
expect(response).to.eventually.have.property("statusCode", 200)
|
|
46
46
|
return expect(response).to.eventually.have.deep.nested.property(
|
|
@@ -49,69 +49,69 @@ it("should load environment", function() {
|
|
|
49
49
|
)
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
it("should pass data to POST", function() {
|
|
52
|
+
it("should pass data to POST", function () {
|
|
53
53
|
const response = sls.invoke("POST api/postit", { body: "boo" })
|
|
54
54
|
return expect(response).to.eventually.have.deep.property("body", {
|
|
55
|
-
message: "postit:boo"
|
|
55
|
+
message: "postit:boo",
|
|
56
56
|
})
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
it("should pass pathParameters with values when present", function() {
|
|
59
|
+
it("should pass pathParameters with values when present", function () {
|
|
60
60
|
const response = sls.invoke("GET api/res1/xxx/res2/yyy")
|
|
61
|
-
return response.then(resp => {
|
|
61
|
+
return response.then((resp) => {
|
|
62
62
|
return expect(resp.body.input).to.have.deep.property("pathParameters", {
|
|
63
63
|
res1ID: "xxx",
|
|
64
|
-
res2ID: "yyy"
|
|
64
|
+
res2ID: "yyy",
|
|
65
65
|
})
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
it("should pass pathParameters along with existing event too", function() {
|
|
69
|
+
it("should pass pathParameters along with existing event too", function () {
|
|
70
70
|
const response = sls.invoke("GET api/res1/xxx/res2/yyy", {
|
|
71
|
-
requestPayload: "boo"
|
|
71
|
+
requestPayload: "boo",
|
|
72
72
|
})
|
|
73
|
-
return response.then(resp => {
|
|
73
|
+
return response.then((resp) => {
|
|
74
74
|
expect(resp.body).to.have.property("input")
|
|
75
75
|
expect(resp.body.input).to.have.deep.property("pathParameters", {
|
|
76
76
|
res1ID: "xxx",
|
|
77
|
-
res2ID: "yyy"
|
|
77
|
+
res2ID: "yyy",
|
|
78
78
|
})
|
|
79
79
|
expect(resp.body.input).to.have.property("requestPayload", "boo")
|
|
80
80
|
})
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
-
it("should pass pathParameters empty when not present", function() {
|
|
83
|
+
it("should pass pathParameters empty when not present", function () {
|
|
84
84
|
const response = sls.invoke("GET api/hello")
|
|
85
|
-
return response.then(resp => {
|
|
85
|
+
return response.then((resp) => {
|
|
86
86
|
return expect(resp.body.input).to.have.deep.property("pathParameters", {})
|
|
87
87
|
})
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
it("should pass greedy path params", function() {
|
|
90
|
+
it("should pass greedy path params", function () {
|
|
91
91
|
const response = sls.invoke("GET api/greedy/blah/blah/blah")
|
|
92
|
-
return response.then(resp => {
|
|
92
|
+
return response.then((resp) => {
|
|
93
93
|
return expect(resp.body.input).to.have.deep.property("pathParameters", {
|
|
94
|
-
money: "blah/blah/blah"
|
|
94
|
+
money: "blah/blah/blah",
|
|
95
95
|
})
|
|
96
96
|
})
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
it("should pass queryStringParameters with values when present", function() {
|
|
99
|
+
it("should pass queryStringParameters with values when present", function () {
|
|
100
100
|
const response = sls.invoke("GET api/with_querystring_params?p1=val1&p2=val2")
|
|
101
|
-
return response.then(resp => {
|
|
101
|
+
return response.then((resp) => {
|
|
102
102
|
return expect(resp.body.input).to.have.deep.property(
|
|
103
103
|
"queryStringParameters",
|
|
104
104
|
{
|
|
105
105
|
p1: "val1",
|
|
106
|
-
p2: "val2"
|
|
106
|
+
p2: "val2",
|
|
107
107
|
}
|
|
108
108
|
)
|
|
109
109
|
})
|
|
110
110
|
})
|
|
111
111
|
|
|
112
|
-
it("should pass queryStringParameters even when not present", function() {
|
|
112
|
+
it("should pass queryStringParameters even when not present", function () {
|
|
113
113
|
const response = sls.invoke("GET api/with_querystring_params")
|
|
114
|
-
return response.then(resp => {
|
|
114
|
+
return response.then((resp) => {
|
|
115
115
|
return expect(resp.body.input).to.have.deep.property(
|
|
116
116
|
"queryStringParameters",
|
|
117
117
|
{}
|
|
@@ -119,50 +119,50 @@ it("should pass queryStringParameters even when not present", function() {
|
|
|
119
119
|
})
|
|
120
120
|
})
|
|
121
121
|
|
|
122
|
-
it("should match urls with query strings and path params in url", function() {
|
|
122
|
+
it("should match urls with query strings and path params in url", function () {
|
|
123
123
|
const response = sls.invoke(
|
|
124
124
|
"GET api/with_querystring_params_and_pathparams/ppvalue?qs1=qsval1"
|
|
125
125
|
)
|
|
126
|
-
return response.then(resp => {
|
|
126
|
+
return response.then((resp) => {
|
|
127
127
|
expect(resp.body.input).to.have.deep.property("queryStringParameters", {
|
|
128
|
-
qs1: "qsval1"
|
|
128
|
+
qs1: "qsval1",
|
|
129
129
|
})
|
|
130
130
|
return expect(resp.body.input).to.have.deep.property("pathParameters", {
|
|
131
|
-
pathparam1: "ppvalue"
|
|
131
|
+
pathparam1: "ppvalue",
|
|
132
132
|
})
|
|
133
133
|
})
|
|
134
134
|
})
|
|
135
135
|
|
|
136
|
-
it("should marshal raw lambda exceptions back as http responses", function() {
|
|
136
|
+
it("should marshal raw lambda exceptions back as http responses", function () {
|
|
137
137
|
const response = sls.invoke("GET api/throwWorld")
|
|
138
138
|
return expect(response).to.eventually.have.property("statusCode", 502)
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
it("should marshal raw handled lambda errors back as http responses", function() {
|
|
141
|
+
it("should marshal raw handled lambda errors back as http responses", function () {
|
|
142
142
|
const response = sls.invoke("GET api/errorWorld")
|
|
143
143
|
return expect(response).to.eventually.have.property("statusCode", 502)
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
-
it("should error if path isn't found", function() {
|
|
146
|
+
it("should error if path isn't found", function () {
|
|
147
147
|
const response = sls.invoke("GET api/DOES_NOT_EXIST")
|
|
148
148
|
return expect(response).to.eventually.be.rejectedWith(
|
|
149
149
|
/^Serverless http event not found for HTTP request/
|
|
150
150
|
)
|
|
151
151
|
})
|
|
152
152
|
|
|
153
|
-
it("should try to find service path in same dir", function() {
|
|
153
|
+
it("should try to find service path in same dir", function () {
|
|
154
154
|
process.chdir(path.join(__dirname))
|
|
155
155
|
const localSls = new ServerlessInvoker()
|
|
156
156
|
expect(localSls.servicePath).to.match(/examples\/comprehensive$/)
|
|
157
157
|
})
|
|
158
158
|
|
|
159
|
-
it("should try to find service path in parent dir", function() {
|
|
159
|
+
it("should try to find service path in parent dir", function () {
|
|
160
160
|
process.chdir(path.join(__dirname, "./subdir"))
|
|
161
161
|
const localSls = new ServerlessInvoker()
|
|
162
162
|
expect(localSls.servicePath).to.match(/examples\/comprehensive$/)
|
|
163
163
|
})
|
|
164
164
|
|
|
165
|
-
it("should fail if serverless.yml not found", function() {
|
|
165
|
+
it("should fail if serverless.yml not found", function () {
|
|
166
166
|
process.chdir(path.join(__dirname, "../../test-data/no-serverless-found"))
|
|
167
167
|
expect(() => new ServerlessInvoker()).to.throw(
|
|
168
168
|
/^Cannot find serverless.yml. Started search in working directory/
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
const assert = require("assert")
|
|
3
3
|
|
|
4
|
-
module.exports.hello = async event => {
|
|
4
|
+
module.exports.hello = async (event) => {
|
|
5
5
|
return {
|
|
6
6
|
statusCode: 200,
|
|
7
7
|
headers: {
|
|
8
|
-
"Content-Type": "application/json"
|
|
8
|
+
"Content-Type": "application/json",
|
|
9
9
|
},
|
|
10
10
|
body: JSON.stringify(
|
|
11
11
|
{
|
|
12
12
|
message: "Go Serverless v1.0! Your function executed successfully!",
|
|
13
|
-
input: event
|
|
13
|
+
input: event,
|
|
14
14
|
},
|
|
15
15
|
null,
|
|
16
16
|
2
|
|
17
|
-
)
|
|
17
|
+
),
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -22,16 +22,16 @@ module.exports.callback = (event, context, callback) => {
|
|
|
22
22
|
const response = {
|
|
23
23
|
statusCode: 200,
|
|
24
24
|
headers: {
|
|
25
|
-
"Content-Type": "application/json"
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
26
|
},
|
|
27
27
|
body: JSON.stringify(
|
|
28
28
|
{
|
|
29
29
|
message: "Go Serverless v1.00! Your function executed successfully!",
|
|
30
|
-
input: event
|
|
30
|
+
input: event,
|
|
31
31
|
},
|
|
32
32
|
null,
|
|
33
33
|
2
|
|
34
|
-
)
|
|
34
|
+
),
|
|
35
35
|
}
|
|
36
36
|
callback(null, response)
|
|
37
37
|
}
|
|
@@ -44,43 +44,43 @@ module.exports.errorWorld = (event, context, callback) => {
|
|
|
44
44
|
callback(new Error("throw world"), null)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
module.exports.with_querystring_params = async event => {
|
|
47
|
+
module.exports.with_querystring_params = async (event) => {
|
|
48
48
|
return {
|
|
49
49
|
statusCode: 200,
|
|
50
50
|
headers: {
|
|
51
|
-
"Content-Type": "application/json"
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
52
|
},
|
|
53
53
|
body: JSON.stringify({
|
|
54
54
|
message: "QueryStringParams on prop",
|
|
55
55
|
queryStringParameters: event.queryStringParameters,
|
|
56
|
-
input: event
|
|
57
|
-
})
|
|
56
|
+
input: event,
|
|
57
|
+
}),
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
module.exports.env = async event => {
|
|
61
|
+
module.exports.env = async (event) => {
|
|
62
62
|
assert(process.env.MY_SIMPLE === "simple value")
|
|
63
63
|
|
|
64
64
|
return {
|
|
65
65
|
statusCode: 200,
|
|
66
66
|
headers: {
|
|
67
|
-
"Content-Type": "application/json"
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
68
|
},
|
|
69
69
|
body: JSON.stringify({
|
|
70
70
|
message: "process.env.MY_SIMPLE==" + process.env.MY_SIMPLE,
|
|
71
|
-
input: event
|
|
72
|
-
})
|
|
71
|
+
input: event,
|
|
72
|
+
}),
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
module.exports.postit = async event => {
|
|
76
|
+
module.exports.postit = async (event) => {
|
|
77
77
|
return {
|
|
78
78
|
statusCode: 200,
|
|
79
79
|
headers: {
|
|
80
|
-
"Content-Type": "application/json"
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
81
|
},
|
|
82
82
|
body: JSON.stringify({
|
|
83
|
-
message: "postit:" + event.body
|
|
84
|
-
})
|
|
83
|
+
message: "postit:" + event.body,
|
|
84
|
+
}),
|
|
85
85
|
}
|
|
86
86
|
}
|
package/index.js
CHANGED
|
@@ -34,7 +34,7 @@ class ServerlessInvoker {
|
|
|
34
34
|
|
|
35
35
|
initializeServerless() {
|
|
36
36
|
const config = {
|
|
37
|
-
servicePath: this.servicePath
|
|
37
|
+
servicePath: this.servicePath,
|
|
38
38
|
}
|
|
39
39
|
const sls = new Serverless(config)
|
|
40
40
|
// NOTE: I've seen sls.init() run very slowly; nearly 500ms!
|
|
@@ -58,9 +58,9 @@ class ServerlessInvoker {
|
|
|
58
58
|
// Read the serverless.yml file
|
|
59
59
|
return this.initializeServerless()
|
|
60
60
|
.then(() => this.loadServerlessEvents())
|
|
61
|
-
.then(httpEvents => {
|
|
61
|
+
.then((httpEvents) => {
|
|
62
62
|
// find the event that matches the specified httpRequest
|
|
63
|
-
let httpEvent = httpEvents.find(e => e.test(httpRequest))
|
|
63
|
+
let httpEvent = httpEvents.find((e) => e.test(httpRequest))
|
|
64
64
|
if (!httpEvent) {
|
|
65
65
|
throw new Error(
|
|
66
66
|
`Serverless http event not found for HTTP request "${httpRequest}" in service path "${this.servicePath}".`
|
|
@@ -75,15 +75,14 @@ class ServerlessInvoker {
|
|
|
75
75
|
httpEvent,
|
|
76
76
|
httpRequest
|
|
77
77
|
),
|
|
78
|
-
queryStringParameters:
|
|
79
|
-
httpRequest
|
|
80
|
-
),
|
|
81
|
-
httpMethod: ServerlessInvoker.parseHttpMethod(httpRequest)
|
|
78
|
+
queryStringParameters:
|
|
79
|
+
ServerlessInvoker.parseQueryStringParameters(httpRequest),
|
|
80
|
+
httpMethod: ServerlessInvoker.parseHttpMethod(httpRequest),
|
|
82
81
|
})
|
|
83
82
|
|
|
84
83
|
return this.loadServerlessEnvironment().then(() => {
|
|
85
84
|
return this.invokeWithLambdaWrapper(httpEvent, event, context)
|
|
86
|
-
.then(response => {
|
|
85
|
+
.then((response) => {
|
|
87
86
|
if (
|
|
88
87
|
response &&
|
|
89
88
|
response.headers &&
|
|
@@ -96,7 +95,7 @@ class ServerlessInvoker {
|
|
|
96
95
|
}
|
|
97
96
|
return response
|
|
98
97
|
})
|
|
99
|
-
.catch(eLambdaFuncError => {
|
|
98
|
+
.catch((eLambdaFuncError) => {
|
|
100
99
|
// In this situation API Gateway returns 502 (bad gateway) and sets the response body to `{"message": "Internal server error"}`. We are adding a bit more detail to the error.
|
|
101
100
|
console.error(
|
|
102
101
|
"serverless-http-invoker error invoking function:",
|
|
@@ -107,8 +106,8 @@ class ServerlessInvoker {
|
|
|
107
106
|
body: {
|
|
108
107
|
message: "Internal server error",
|
|
109
108
|
test_debug_error_message: eLambdaFuncError.toString(),
|
|
110
|
-
test_debug_error_stack: eLambdaFuncError.stack
|
|
111
|
-
}
|
|
109
|
+
test_debug_error_stack: eLambdaFuncError.stack,
|
|
110
|
+
},
|
|
112
111
|
}
|
|
113
112
|
return response
|
|
114
113
|
})
|
|
@@ -184,23 +183,23 @@ class ServerlessInvoker {
|
|
|
184
183
|
loadServerlessEvents() {
|
|
185
184
|
let funcs = this.serverless.service
|
|
186
185
|
.getAllFunctions()
|
|
187
|
-
.map(fname => {
|
|
186
|
+
.map((fname) => {
|
|
188
187
|
let funcObj = this.serverless.service.getFunction(fname)
|
|
189
188
|
let events = this.serverless.service.getAllEventsInFunction(fname)
|
|
190
189
|
let f = {
|
|
191
190
|
name: fname,
|
|
192
191
|
handler: funcObj.handler,
|
|
193
192
|
events: events.filter(
|
|
194
|
-
e => Object.keys(e).includes("http") && e.http !== null
|
|
195
|
-
)
|
|
193
|
+
(e) => Object.keys(e).includes("http") && e.http !== null
|
|
194
|
+
),
|
|
196
195
|
}
|
|
197
196
|
return f
|
|
198
197
|
})
|
|
199
|
-
.filter(f => f.events.length > 0)
|
|
200
|
-
.map(f => {
|
|
201
|
-
f.events = f.events.map(evt => {
|
|
198
|
+
.filter((f) => f.events.length > 0)
|
|
199
|
+
.map((f) => {
|
|
200
|
+
f.events = f.events.map((evt) => {
|
|
202
201
|
// add a path parser regex:
|
|
203
|
-
RegExp.escape = function(s) {
|
|
202
|
+
RegExp.escape = function (s) {
|
|
204
203
|
// https://stackoverflow.com/a/3561711/51061
|
|
205
204
|
return s.replace(/[-/\\^$*+?.()|[\]]/g, "\\$&")
|
|
206
205
|
}
|
|
@@ -232,11 +231,11 @@ class ServerlessInvoker {
|
|
|
232
231
|
let matchPathParamNames = new RegExp(matchPathParamNamesPattern, "gi")
|
|
233
232
|
let pathParamNames = matchPathParamNames.exec(path).slice(1) // the first element is full matched text so slice it off
|
|
234
233
|
// remove the surrounding bracket characters:
|
|
235
|
-
pathParamNames = pathParamNames.map(p =>
|
|
234
|
+
pathParamNames = pathParamNames.map((p) =>
|
|
236
235
|
p.replace(/^\{([^}]+)\}$/, "$1")
|
|
237
236
|
)
|
|
238
237
|
// remove the '+' postfix if it exists
|
|
239
|
-
pathParamNames = pathParamNames.map(p =>
|
|
238
|
+
pathParamNames = pathParamNames.map((p) =>
|
|
240
239
|
p.endsWith("+") ? p.substring(0, p.length - 1) : p
|
|
241
240
|
)
|
|
242
241
|
// console.log('pathParamNames:', pathParamNames, 'path:', path)
|
|
@@ -263,11 +262,11 @@ class ServerlessInvoker {
|
|
|
263
262
|
return Object.assign(evt.http, {
|
|
264
263
|
matcher: matcher,
|
|
265
264
|
pathParamNames: pathParamNames,
|
|
266
|
-
test: request => {
|
|
265
|
+
test: (request) => {
|
|
267
266
|
const result = matcher.test(request)
|
|
268
267
|
// console.log(`${method} ${path}: ${request} == ${result} \n pattern:${matcher.source}`)
|
|
269
268
|
return result
|
|
270
|
-
}
|
|
269
|
+
},
|
|
271
270
|
})
|
|
272
271
|
})
|
|
273
272
|
return f
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serverless-http-invoker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Locally invoke Serverless functions via their HTTP event as specified in Serverless.yml for testing.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Scott Willeke <scott@willeke.com> (https:/scott.willeke.com/)",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"tdd"
|
|
25
25
|
],
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=14"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"serverless": "^1.27.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"chai": "^4.
|
|
49
|
+
"chai": "^4.3.6",
|
|
50
50
|
"chai-as-promised": "^7.1.1",
|
|
51
|
-
"coveralls": "^3.
|
|
52
|
-
"mocha": "^
|
|
53
|
-
"nyc": "^15.
|
|
54
|
-
"prettier": "^
|
|
51
|
+
"coveralls": "^3.1.1",
|
|
52
|
+
"mocha": "^10.0.0",
|
|
53
|
+
"nyc": "^15.1.0",
|
|
54
|
+
"prettier": "^2.7.1",
|
|
55
55
|
"serverless": "^2.46.0"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/release.config.js
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
name: dependabot validate
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
paths:
|
|
6
|
-
- ".github/dependabot.yml"
|
|
7
|
-
- ".github/workflows/dependabot-validate.yml"
|
|
8
|
-
jobs:
|
|
9
|
-
validate:
|
|
10
|
-
runs-on: ubuntu-20.04
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v2
|
|
13
|
-
- uses: marocchino/validate-dependabot@v1
|
|
14
|
-
id: validate
|
|
15
|
-
- uses: marocchino/sticky-pull-request-comment@v2
|
|
16
|
-
if: always()
|
|
17
|
-
with:
|
|
18
|
-
header: validate-dependabot
|
|
19
|
-
message: ${{ steps.validate.outputs.markdown }}
|