mastra 0.1.57-unstable.35 → 0.1.57-unstable.36
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 +2 -16
- package/node_modules/express/History.md +0 -3647
- package/node_modules/express/LICENSE +0 -24
- package/node_modules/express/Readme.md +0 -260
- package/node_modules/express/index.js +0 -11
- package/node_modules/express/lib/application.js +0 -661
- package/node_modules/express/lib/express.js +0 -116
- package/node_modules/express/lib/middleware/init.js +0 -43
- package/node_modules/express/lib/middleware/query.js +0 -47
- package/node_modules/express/lib/request.js +0 -525
- package/node_modules/express/lib/response.js +0 -1179
- package/node_modules/express/lib/router/index.js +0 -673
- package/node_modules/express/lib/router/layer.js +0 -181
- package/node_modules/express/lib/router/route.js +0 -230
- package/node_modules/express/lib/utils.js +0 -303
- package/node_modules/express/lib/view.js +0 -182
- package/node_modules/express/package.json +0 -98
- package/node_modules/express-jsdoc-swagger/.all-contributorsrc +0 -168
- package/node_modules/express-jsdoc-swagger/.eslintignore +0 -6
- package/node_modules/express-jsdoc-swagger/.eslintrc.json +0 -37
- package/node_modules/express-jsdoc-swagger/CODE_OF_CONDUCT.md +0 -76
- package/node_modules/express-jsdoc-swagger/CONTRIBUTING.md +0 -55
- package/node_modules/express-jsdoc-swagger/LICENSE.md +0 -21
- package/node_modules/express-jsdoc-swagger/README.md +0 -376
- package/node_modules/express-jsdoc-swagger/commitlint.config.js +0 -24
- package/node_modules/express-jsdoc-swagger/config/default.js +0 -18
- package/node_modules/express-jsdoc-swagger/config/swaggerEvents.js +0 -5
- package/node_modules/express-jsdoc-swagger/consumers/getOnlyComments.js +0 -21
- package/node_modules/express-jsdoc-swagger/consumers/globFilesMatches.js +0 -50
- package/node_modules/express-jsdoc-swagger/consumers/jsdocInfo.js +0 -20
- package/node_modules/express-jsdoc-swagger/consumers/readFiles.js +0 -9
- package/node_modules/express-jsdoc-swagger/consumers/utils/getComments.js +0 -13
- package/node_modules/express-jsdoc-swagger/consumers/utils/readFile.js +0 -15
- package/node_modules/express-jsdoc-swagger/index.d.ts +0 -65
- package/node_modules/express-jsdoc-swagger/index.js +0 -60
- package/node_modules/express-jsdoc-swagger/package.json +0 -59
- package/node_modules/express-jsdoc-swagger/processSwagger.js +0 -45
- package/node_modules/express-jsdoc-swagger/swaggerEvents.js +0 -35
- package/node_modules/express-jsdoc-swagger/transforms/basic/contact.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/basic/index.js +0 -10
- package/node_modules/express-jsdoc-swagger/transforms/basic/info.js +0 -26
- package/node_modules/express-jsdoc-swagger/transforms/basic/license.js +0 -14
- package/node_modules/express-jsdoc-swagger/transforms/basic/servers.js +0 -20
- package/node_modules/express-jsdoc-swagger/transforms/components/index.js +0 -130
- package/node_modules/express-jsdoc-swagger/transforms/index.js +0 -13
- package/node_modules/express-jsdoc-swagger/transforms/paths/content.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/paths/examples.js +0 -98
- package/node_modules/express-jsdoc-swagger/transforms/paths/formParams.js +0 -40
- package/node_modules/express-jsdoc-swagger/transforms/paths/index.js +0 -127
- package/node_modules/express-jsdoc-swagger/transforms/paths/parameters.js +0 -80
- package/node_modules/express-jsdoc-swagger/transforms/paths/requestBody.js +0 -65
- package/node_modules/express-jsdoc-swagger/transforms/paths/responses.js +0 -55
- package/node_modules/express-jsdoc-swagger/transforms/paths/schema.js +0 -33
- package/node_modules/express-jsdoc-swagger/transforms/paths/security.js +0 -31
- package/node_modules/express-jsdoc-swagger/transforms/paths/validStatusCodes.js +0 -64
- package/node_modules/express-jsdoc-swagger/transforms/security/index.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/tags/index.js +0 -41
- package/node_modules/express-jsdoc-swagger/transforms/utils/arrays.js +0 -12
- package/node_modules/express-jsdoc-swagger/transforms/utils/combineSchema.js +0 -67
- package/node_modules/express-jsdoc-swagger/transforms/utils/enumValues.js +0 -6
- package/node_modules/express-jsdoc-swagger/transforms/utils/errorMessage.js +0 -8
- package/node_modules/express-jsdoc-swagger/transforms/utils/formatDescription.js +0 -35
- package/node_modules/express-jsdoc-swagger/transforms/utils/formatExamples.js +0 -25
- package/node_modules/express-jsdoc-swagger/transforms/utils/generator.js +0 -6
- package/node_modules/express-jsdoc-swagger/transforms/utils/httpMethods.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/utils/mapDescription.js +0 -5
- package/node_modules/express-jsdoc-swagger/transforms/utils/refSchema.js +0 -48
- package/node_modules/express-jsdoc-swagger/transforms/utils/setProperty.js +0 -25
- package/node_modules/express-jsdoc-swagger/transforms/utils/tags.js +0 -16
- package/node_modules/express-jsdoc-swagger/transforms/utils/validateTypes.js +0 -11
- package/node_modules/serverless-http/LICENSE.txt +0 -33
- package/node_modules/serverless-http/README.md +0 -117
- package/node_modules/serverless-http/lib/finish.js +0 -42
- package/node_modules/serverless-http/lib/framework/get-framework.js +0 -79
- package/node_modules/serverless-http/lib/provider/aws/clean-up-event.js +0 -98
- package/node_modules/serverless-http/lib/provider/aws/create-request.js +0 -110
- package/node_modules/serverless-http/lib/provider/aws/format-response.js +0 -45
- package/node_modules/serverless-http/lib/provider/aws/index.js +0 -15
- package/node_modules/serverless-http/lib/provider/aws/is-binary.js +0 -42
- package/node_modules/serverless-http/lib/provider/aws/sanitize-headers.js +0 -21
- package/node_modules/serverless-http/lib/provider/azure/clean-up-request.js +0 -41
- package/node_modules/serverless-http/lib/provider/azure/create-request.js +0 -45
- package/node_modules/serverless-http/lib/provider/azure/format-response.js +0 -18
- package/node_modules/serverless-http/lib/provider/azure/index.js +0 -13
- package/node_modules/serverless-http/lib/provider/azure/is-binary.js +0 -42
- package/node_modules/serverless-http/lib/provider/azure/sanitize-headers.js +0 -23
- package/node_modules/serverless-http/lib/provider/azure/set-cookie.json +0 -1
- package/node_modules/serverless-http/lib/provider/get-provider.js +0 -17
- package/node_modules/serverless-http/lib/request.js +0 -38
- package/node_modules/serverless-http/lib/response.js +0 -135
- package/node_modules/serverless-http/package.json +0 -93
- package/node_modules/serverless-http/serverless-http.d.ts +0 -41
- package/node_modules/serverless-http/serverless-http.js +0 -23
- package/node_modules/swagger-ui-express/LICENSE +0 -22
- package/node_modules/swagger-ui-express/README.md +0 -360
- package/node_modules/swagger-ui-express/index.js +0 -311
- package/node_modules/swagger-ui-express/package.json +0 -58
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const validRequestBodyMethods = {
|
|
2
|
-
get: false,
|
|
3
|
-
delete: true,
|
|
4
|
-
head: false,
|
|
5
|
-
post: true,
|
|
6
|
-
put: true,
|
|
7
|
-
connect: true,
|
|
8
|
-
options: true,
|
|
9
|
-
trace: true,
|
|
10
|
-
patch: true,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const validHTTPMethod = method => Object.keys(validRequestBodyMethods).includes(method);
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
validRequestBodyMethods,
|
|
17
|
-
validHTTPMethod,
|
|
18
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const validateTypes = require('./validateTypes');
|
|
2
|
-
|
|
3
|
-
const REF_ROUTE = '#/components/schemas/';
|
|
4
|
-
|
|
5
|
-
const refSchema = value => {
|
|
6
|
-
// support * @return {array<Song|Album>} 200 - fetch Home Content response
|
|
7
|
-
if (value && value.type === 'UnionType') {
|
|
8
|
-
const items = [];
|
|
9
|
-
value.elements.forEach(el => {
|
|
10
|
-
const isPrimitiveType = validateTypes(el.name);
|
|
11
|
-
items.push(isPrimitiveType ? { type: el.name } : { $ref: `${REF_ROUTE}${el.name}` });
|
|
12
|
-
});
|
|
13
|
-
return {
|
|
14
|
-
anyOf: items,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// support * @property {anyOf|Song[]|Album|string|string[]} firstSong
|
|
19
|
-
if (value && value.expression && value.expression.name.toLowerCase() === 'array' && value.type === 'TypeApplication') {
|
|
20
|
-
const isPrimitiveType = validateTypes(value.applications[0].name);
|
|
21
|
-
return isPrimitiveType ? {
|
|
22
|
-
type: 'array',
|
|
23
|
-
items: { type: value.applications[0].name },
|
|
24
|
-
} : {
|
|
25
|
-
type: 'array',
|
|
26
|
-
items: { $ref: `${REF_ROUTE}${value.applications[0].name}` },
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!value) return {};
|
|
31
|
-
|
|
32
|
-
const nameValue = value.name || value;
|
|
33
|
-
// support null
|
|
34
|
-
if (nameValue.type === 'NullLiteral') return { nullable: true };
|
|
35
|
-
|
|
36
|
-
const isPrimitive = validateTypes(nameValue);
|
|
37
|
-
return isPrimitive ? { type: nameValue } : { $ref: `${REF_ROUTE}${nameValue}` };
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const formatRefSchema = (applications = []) => applications.reduce((itemAcc, itemTypes) => ({
|
|
41
|
-
...itemAcc,
|
|
42
|
-
...refSchema(itemTypes),
|
|
43
|
-
}), {});
|
|
44
|
-
|
|
45
|
-
module.exports = {
|
|
46
|
-
refSchema,
|
|
47
|
-
formatRefSchema,
|
|
48
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const errorMessage = require('./errorMessage');
|
|
2
|
-
|
|
3
|
-
const setProperty = entity => {
|
|
4
|
-
const requiredError = (key, item) => (
|
|
5
|
-
new Error(`Key ${key} is required in item ${JSON.stringify(item)} for Entity ${entity}`)
|
|
6
|
-
);
|
|
7
|
-
|
|
8
|
-
const warnType = (type, value) => (
|
|
9
|
-
errorMessage(`${type} is not valid with value ${value} for Entity ${entity}`)
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return (item, key, options) => {
|
|
13
|
-
if (!item || !key || !options) {
|
|
14
|
-
throw (new Error('item, key and options para are required'));
|
|
15
|
-
}
|
|
16
|
-
const value = item[key];
|
|
17
|
-
if (options.required && value === undefined) throw requiredError(key, item);
|
|
18
|
-
if (value === undefined || value === null) return options.defaultValue;
|
|
19
|
-
// eslint-disable-next-line
|
|
20
|
-
if (typeof (value) !== options.type) warnType(options.type, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
module.exports = setProperty;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const mapDescription = require('./mapDescription');
|
|
2
|
-
|
|
3
|
-
const getTagInfo = (tags, key) => tags.find(({ title }) => title === key);
|
|
4
|
-
|
|
5
|
-
const getTagsInfo = (tags, key) => tags.filter(({ title }) => title === key);
|
|
6
|
-
|
|
7
|
-
const formatDescriptionTag = desc => {
|
|
8
|
-
const [name, description] = mapDescription(desc);
|
|
9
|
-
return { name, description };
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
getTagInfo,
|
|
14
|
-
getTagsInfo,
|
|
15
|
-
formatDescriptionTag,
|
|
16
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2016 Doug Moscrop
|
|
4
|
-
|
|
5
|
-
The following license applies to all parts of this software except as
|
|
6
|
-
documented below:
|
|
7
|
-
|
|
8
|
-
====
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
|
18
|
-
copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
-
SOFTWARE.
|
|
27
|
-
|
|
28
|
-
====
|
|
29
|
-
|
|
30
|
-
All files located in the node_modules and external directories are
|
|
31
|
-
externally maintained libraries used by this software which have their
|
|
32
|
-
own licenses; we recommend you read them, as their terms may differ from
|
|
33
|
-
the terms above.
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
# serverless-http
|
|
2
|
-
|
|
3
|
-
[](https://travis-ci.org/dougmoscrop/serverless-http)
|
|
4
|
-
|
|
5
|
-
## Description
|
|
6
|
-
|
|
7
|
-
This module allows you to 'wrap' your API for serverless use. No HTTP server, no ports or sockets. Just your code in the same execution pipeline you are already familiar with.
|
|
8
|
-
|
|
9
|
-
## Sponsors
|
|
10
|
-
|
|
11
|
-
Thank you to Upstash for reaching out to sponsor this project!
|
|
12
|
-
|
|
13
|
-
<table>
|
|
14
|
-
<tr>
|
|
15
|
-
<td>
|
|
16
|
-
<img width="1000" height="0">
|
|
17
|
-
<a href="https://upstash.com/?utm_source=serverless-http" >
|
|
18
|
-
<img src="https://raw.githubusercontent.com/upstash/sponsorship/master/redis.png" alt="Upstash" width="260" align="right">
|
|
19
|
-
</a>
|
|
20
|
-
<h3>Upstash: Serverless Database for Redis</h3>
|
|
21
|
-
|
|
22
|
-
<ul>
|
|
23
|
-
<li>Serverless Redis with global replication and durable storage</li>
|
|
24
|
-
<li>Price scales to zero with per request pricing</li>
|
|
25
|
-
<li>Built-in REST API designed for serverless and edge functions</li>
|
|
26
|
-
</ul>
|
|
27
|
-
|
|
28
|
-
[Start for free in 30 seconds!](https://upstash.com/?utm_source=serverless-http)
|
|
29
|
-
</td>
|
|
30
|
-
</tr>
|
|
31
|
-
</table>
|
|
32
|
-
|
|
33
|
-
## Support
|
|
34
|
-
|
|
35
|
-
### Supported Frameworks
|
|
36
|
-
(* Experimental)
|
|
37
|
-
|
|
38
|
-
* Node (http.createServer)
|
|
39
|
-
* Connect
|
|
40
|
-
* Express
|
|
41
|
-
* Koa
|
|
42
|
-
* Restana
|
|
43
|
-
* Sails *
|
|
44
|
-
* Hapi *
|
|
45
|
-
* Fastify *
|
|
46
|
-
* Restify *
|
|
47
|
-
* Polka *
|
|
48
|
-
* Loopback *
|
|
49
|
-
|
|
50
|
-
### Supported Providers
|
|
51
|
-
|
|
52
|
-
* AWS
|
|
53
|
-
* Azure (Experimental, untested, probably outdated)
|
|
54
|
-
|
|
55
|
-
## Examples
|
|
56
|
-
|
|
57
|
-
Please check the `examples` folder!
|
|
58
|
-
|
|
59
|
-
### Usage example using the Koa framework
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
const serverless = require('serverless-http');
|
|
63
|
-
const Koa = require('koa'); // or any supported framework
|
|
64
|
-
|
|
65
|
-
const app = new Koa();
|
|
66
|
-
|
|
67
|
-
app.use(/* register your middleware as normal */);
|
|
68
|
-
|
|
69
|
-
// this is it!
|
|
70
|
-
module.exports.handler = serverless(app);
|
|
71
|
-
|
|
72
|
-
// or as a promise
|
|
73
|
-
const handler = serverless(app);
|
|
74
|
-
module.exports.handler = async (event, context) => {
|
|
75
|
-
// you can do other things here
|
|
76
|
-
const result = await handler(event, context);
|
|
77
|
-
// and here
|
|
78
|
-
return result;
|
|
79
|
-
};
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Usage example using the Express framework with Azure
|
|
83
|
-
|
|
84
|
-
```javascript
|
|
85
|
-
|
|
86
|
-
const serverless = require('serverless-http');
|
|
87
|
-
const express = require('express');
|
|
88
|
-
|
|
89
|
-
const app = express();
|
|
90
|
-
|
|
91
|
-
app.use(/* register your middleware as normal */);
|
|
92
|
-
|
|
93
|
-
const handler = serverless(app, { provider: 'azure' });
|
|
94
|
-
module.exports.funcName = async (context, req) => {
|
|
95
|
-
context.res = await handler(context, req);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Other examples
|
|
101
|
-
[json-server-less-λ](https://github.com/pharindoko/json-server-less-lambda) - using serverless-http with json-server and serverless framework in AWS
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
## Limitations
|
|
105
|
-
|
|
106
|
-
Your code is running in a serverless environment. You cannot rely on your server being 'up' in the sense that you can/should not use in-memory sessions, web sockets, etc. You are also subject to provider specific restrictions on request/response size, duration, etc.
|
|
107
|
-
|
|
108
|
-
> Think of this as a familiar way of expressing your app logic, *not* trying to make serverless do something it cannot.
|
|
109
|
-
|
|
110
|
-
## Contributing
|
|
111
|
-
|
|
112
|
-
Pull requests are welcome! Especially test scenarios for different situations and configurations.
|
|
113
|
-
|
|
114
|
-
## Further Reading
|
|
115
|
-
|
|
116
|
-
Here are some [more detailed examples](./docs/EXAMPLES.md) and [advanced configuration options](./docs/ADVANCED.md) as well as [provider-specific documentation](./docs/PROVIDERS.md)
|
|
117
|
-
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = async function finish(item, transform, ...details) {
|
|
4
|
-
await new Promise((resolve, reject) => {
|
|
5
|
-
if (item.finished || item.complete) {
|
|
6
|
-
resolve();
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
let finished = false;
|
|
11
|
-
|
|
12
|
-
function done(err) {
|
|
13
|
-
if (finished) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
finished = true;
|
|
18
|
-
|
|
19
|
-
item.removeListener('error', done);
|
|
20
|
-
item.removeListener('end', done);
|
|
21
|
-
item.removeListener('finish', done);
|
|
22
|
-
|
|
23
|
-
if (err) {
|
|
24
|
-
reject(err);
|
|
25
|
-
} else {
|
|
26
|
-
resolve();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
item.once('error', done);
|
|
31
|
-
item.once('end', done);
|
|
32
|
-
item.once('finish', done);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (typeof transform === 'function') {
|
|
36
|
-
await transform(item, ...details);
|
|
37
|
-
} else if (typeof transform === 'object' && transform !== null) {
|
|
38
|
-
Object.assign(item, transform);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return item;
|
|
42
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const http = require('http')
|
|
4
|
-
const Response = require('../response');
|
|
5
|
-
|
|
6
|
-
function common(cb) {
|
|
7
|
-
return request => {
|
|
8
|
-
const response = new Response(request);
|
|
9
|
-
|
|
10
|
-
cb(request, response);
|
|
11
|
-
|
|
12
|
-
return response;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = function getFramework(app) {
|
|
17
|
-
if (app instanceof http.Server) {
|
|
18
|
-
return request => {
|
|
19
|
-
const response = new Response(request);
|
|
20
|
-
app.emit('request', request, response)
|
|
21
|
-
return response
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (typeof app.callback === 'function') {
|
|
26
|
-
return common(app.callback());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (typeof app.handle === 'function') {
|
|
30
|
-
return common((request, response) => {
|
|
31
|
-
app.handle(request, response);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (typeof app.handler === 'function') {
|
|
36
|
-
return common((request, response) => {
|
|
37
|
-
app.handler(request, response);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (typeof app._onRequest === 'function') {
|
|
42
|
-
return common((request, response) => {
|
|
43
|
-
app._onRequest(request, response);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (typeof app === 'function') {
|
|
48
|
-
return common(app);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (app.router && typeof app.router.route == 'function') {
|
|
52
|
-
return common((req, res) => {
|
|
53
|
-
const { url, method, headers, body } = req;
|
|
54
|
-
app.router.route({ url, method, headers, body }, res);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (app._core && typeof app._core._dispatch === 'function') {
|
|
59
|
-
return common(app._core._dispatch({
|
|
60
|
-
app
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (typeof app.inject === 'function') {
|
|
65
|
-
return async request => {
|
|
66
|
-
const { method, url, headers, body } = request;
|
|
67
|
-
|
|
68
|
-
const res = await app.inject({ method, url, headers, payload: body })
|
|
69
|
-
|
|
70
|
-
return Response.from(res);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (typeof app.main === 'function') {
|
|
75
|
-
return common(app.main);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
throw new Error('Unsupported framework');
|
|
79
|
-
};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function removeBasePath(path = '/', basePath) {
|
|
4
|
-
if (basePath) {
|
|
5
|
-
const basePathIndex = path.indexOf(basePath);
|
|
6
|
-
|
|
7
|
-
if (basePathIndex > -1) {
|
|
8
|
-
return path.substr(basePathIndex + basePath.length) || '/';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return path;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function isString(value)
|
|
16
|
-
{
|
|
17
|
-
return (typeof value === 'string' || value instanceof String);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ELBs will pass spaces as + symbols, and decodeURIComponent doesn't decode + symbols. So we need to convert them into something it can convert
|
|
21
|
-
function specialDecodeURIComponent(value)
|
|
22
|
-
{
|
|
23
|
-
if(!isString(value))
|
|
24
|
-
{
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let decoded;
|
|
29
|
-
try {
|
|
30
|
-
decoded = decodeURIComponent(value.replace(/[+]/g, "%20"));
|
|
31
|
-
} catch (err) {
|
|
32
|
-
decoded = value.replace(/[+]/g, "%20");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return decoded;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function recursiveURLDecode(value) {
|
|
39
|
-
|
|
40
|
-
if (isString(value)) {
|
|
41
|
-
return specialDecodeURIComponent(value);
|
|
42
|
-
} else if (Array.isArray(value)) {
|
|
43
|
-
|
|
44
|
-
const decodedArray = [];
|
|
45
|
-
|
|
46
|
-
for (let index in value) {
|
|
47
|
-
decodedArray.push(recursiveURLDecode(value[index]));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return decodedArray;
|
|
51
|
-
|
|
52
|
-
} else if (value instanceof Object) {
|
|
53
|
-
|
|
54
|
-
const decodedObject = {};
|
|
55
|
-
|
|
56
|
-
for (let key of Object.keys(value)) {
|
|
57
|
-
decodedObject[specialDecodeURIComponent(key)] = recursiveURLDecode(value[key]);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return decodedObject;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = function cleanupEvent(evt, options) {
|
|
67
|
-
const event = evt || {};
|
|
68
|
-
|
|
69
|
-
event.requestContext = event.requestContext || {};
|
|
70
|
-
event.body = event.body || '';
|
|
71
|
-
event.headers = event.headers || {};
|
|
72
|
-
|
|
73
|
-
// Events coming from AWS Elastic Load Balancers do not automatically urldecode query parameters (unlike API Gateway). So we need to check for that and automatically decode them
|
|
74
|
-
// to normalize the request between the two.
|
|
75
|
-
if ('elb' in event.requestContext) {
|
|
76
|
-
|
|
77
|
-
if (event.multiValueQueryStringParameters) {
|
|
78
|
-
event.multiValueQueryStringParameters = recursiveURLDecode(event.multiValueQueryStringParameters);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (event.queryStringParameters) {
|
|
82
|
-
event.queryStringParameters = recursiveURLDecode(event.queryStringParameters);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (event.version === '2.0') {
|
|
88
|
-
event.requestContext.authorizer = event.requestContext.authorizer || {};
|
|
89
|
-
event.requestContext.http.method = event.requestContext.http.method || 'GET';
|
|
90
|
-
event.rawPath = removeBasePath(event.requestPath || event.rawPath, options.basePath);
|
|
91
|
-
} else {
|
|
92
|
-
event.requestContext.identity = event.requestContext.identity || {};
|
|
93
|
-
event.httpMethod = event.httpMethod || 'GET';
|
|
94
|
-
event.path = removeBasePath(event.requestPath || event.path, options.basePath);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return event;
|
|
98
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const URL = require('url');
|
|
4
|
-
|
|
5
|
-
const Request = require('../../request');
|
|
6
|
-
|
|
7
|
-
function requestMethod(event) {
|
|
8
|
-
if (event.version === '2.0') {
|
|
9
|
-
return event.requestContext.http.method;
|
|
10
|
-
}
|
|
11
|
-
return event.httpMethod;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function requestRemoteAddress(event) {
|
|
15
|
-
if (event.version === '2.0') {
|
|
16
|
-
return event.requestContext.http.sourceIp;
|
|
17
|
-
}
|
|
18
|
-
return event.requestContext.identity.sourceIp;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function requestHeaders(event) {
|
|
22
|
-
const initialHeader =
|
|
23
|
-
event.version === '2.0' && Array.isArray(event.cookies)
|
|
24
|
-
? { cookie: event.cookies.join('; ') }
|
|
25
|
-
: {};
|
|
26
|
-
|
|
27
|
-
if (event.multiValueHeaders) {
|
|
28
|
-
Object.keys(event.multiValueHeaders).reduce((headers, key) => {
|
|
29
|
-
headers[key.toLowerCase()] = event.multiValueHeaders[key].join(', ');
|
|
30
|
-
return headers;
|
|
31
|
-
}, initialHeader);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return Object.keys(event.headers).reduce((headers, key) => {
|
|
35
|
-
headers[key.toLowerCase()] = event.headers[key];
|
|
36
|
-
return headers;
|
|
37
|
-
}, initialHeader);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function requestBody(event) {
|
|
41
|
-
const type = typeof event.body;
|
|
42
|
-
|
|
43
|
-
if (Buffer.isBuffer(event.body)) {
|
|
44
|
-
return event.body;
|
|
45
|
-
} else if (type === 'string') {
|
|
46
|
-
return Buffer.from(event.body, event.isBase64Encoded ? 'base64' : 'utf8');
|
|
47
|
-
} else if (type === 'object') {
|
|
48
|
-
return Buffer.from(JSON.stringify(event.body));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
throw new Error(`Unexpected event.body type: ${typeof event.body}`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function requestUrl(event) {
|
|
55
|
-
if (event.version === '2.0') {
|
|
56
|
-
return URL.format({
|
|
57
|
-
pathname: event.rawPath,
|
|
58
|
-
search: event.rawQueryString,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
// Normalize all query params into a single query string.
|
|
62
|
-
const query = event.multiValueQueryStringParameters || {};
|
|
63
|
-
if (event.queryStringParameters) {
|
|
64
|
-
Object.keys(event.queryStringParameters).forEach((key) => {
|
|
65
|
-
if (Array.isArray(query[key])) {
|
|
66
|
-
if (!query[key].includes(event.queryStringParameters[key])) {
|
|
67
|
-
query[key].push(event.queryStringParameters[key]);
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
query[key] = [event.queryStringParameters[key]];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return URL.format({
|
|
75
|
-
pathname: event.path,
|
|
76
|
-
query: query,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = (event, context, options) => {
|
|
81
|
-
const method = requestMethod(event);
|
|
82
|
-
const remoteAddress = requestRemoteAddress(event);
|
|
83
|
-
const headers = requestHeaders(event);
|
|
84
|
-
const body = requestBody(event);
|
|
85
|
-
const url = requestUrl(event);
|
|
86
|
-
|
|
87
|
-
if (typeof options.requestId === 'string' && options.requestId.length > 0) {
|
|
88
|
-
const header = options.requestId.toLowerCase();
|
|
89
|
-
const requestId = headers[header] || event.requestContext.requestId;
|
|
90
|
-
if (requestId) {
|
|
91
|
-
headers[header] = requestId;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const req = new Request({
|
|
96
|
-
method,
|
|
97
|
-
headers,
|
|
98
|
-
body,
|
|
99
|
-
remoteAddress,
|
|
100
|
-
url,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
req.requestContext = event.requestContext;
|
|
104
|
-
req.apiGateway = {
|
|
105
|
-
event,
|
|
106
|
-
context,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return req;
|
|
110
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const isBinary = require('./is-binary');
|
|
4
|
-
const Response = require('../../response');
|
|
5
|
-
const sanitizeHeaders = require('./sanitize-headers');
|
|
6
|
-
|
|
7
|
-
module.exports = (event, response, options) => {
|
|
8
|
-
const { statusCode } = response;
|
|
9
|
-
const {headers, multiValueHeaders } = sanitizeHeaders(Response.headers(response));
|
|
10
|
-
|
|
11
|
-
let cookies = [];
|
|
12
|
-
|
|
13
|
-
if (multiValueHeaders['set-cookie']) {
|
|
14
|
-
cookies = multiValueHeaders['set-cookie'];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const isBase64Encoded = isBinary(headers, options);
|
|
18
|
-
const encoding = isBase64Encoded ? 'base64' : 'utf8';
|
|
19
|
-
let body = Response.body(response).toString(encoding);
|
|
20
|
-
|
|
21
|
-
if (headers['transfer-encoding'] === 'chunked' || response.chunkedEncoding) {
|
|
22
|
-
const raw = Response.body(response).toString().split('\r\n');
|
|
23
|
-
const parsed = [];
|
|
24
|
-
for (let i = 0; i < raw.length; i +=2) {
|
|
25
|
-
const size = parseInt(raw[i], 16);
|
|
26
|
-
const value = raw[i + 1];
|
|
27
|
-
if (value) {
|
|
28
|
-
parsed.push(value.substring(0, size));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
body = parsed.join('')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let formattedResponse = { statusCode, headers, isBase64Encoded, body };
|
|
35
|
-
|
|
36
|
-
if (event.version === '2.0' && cookies.length) {
|
|
37
|
-
formattedResponse['cookies'] = cookies;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if ((!event.version || event.version === '1.0') && Object.keys(multiValueHeaders).length) {
|
|
41
|
-
formattedResponse['multiValueHeaders'] = multiValueHeaders;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return formattedResponse;
|
|
45
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const cleanUpEvent = require('./clean-up-event');
|
|
2
|
-
|
|
3
|
-
const createRequest = require('./create-request');
|
|
4
|
-
const formatResponse = require('./format-response');
|
|
5
|
-
|
|
6
|
-
module.exports = options => {
|
|
7
|
-
return getResponse => async (event_, context = {}) => {
|
|
8
|
-
const event = cleanUpEvent(event_, options);
|
|
9
|
-
|
|
10
|
-
const request = createRequest(event, context, options);
|
|
11
|
-
const response = await getResponse(request, event, context);
|
|
12
|
-
|
|
13
|
-
return formatResponse(event, response, options);
|
|
14
|
-
};
|
|
15
|
-
};
|