aws-lambda-api-tools 0.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.
- package/README.md +212 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/authorization-helper.d.ts +3 -0
- package/dist/lib/authorization-helper.d.ts.map +1 -0
- package/dist/lib/authorization-helper.js +14 -0
- package/dist/lib/authorization-helper.js.map +1 -0
- package/dist/lib/custom-error.d.ts +8 -0
- package/dist/lib/custom-error.d.ts.map +1 -0
- package/dist/lib/custom-error.js +19 -0
- package/dist/lib/custom-error.js.map +1 -0
- package/dist/lib/lambda-route-proxy-entry-handler.d.ts +10 -0
- package/dist/lib/lambda-route-proxy-entry-handler.d.ts.map +1 -0
- package/dist/lib/lambda-route-proxy-entry-handler.js +67 -0
- package/dist/lib/lambda-route-proxy-entry-handler.js.map +1 -0
- package/dist/lib/lambda-route-proxy-path-not-found.d.ts +3 -0
- package/dist/lib/lambda-route-proxy-path-not-found.d.ts.map +1 -0
- package/dist/lib/lambda-route-proxy-path-not-found.js +27 -0
- package/dist/lib/lambda-route-proxy-path-not-found.js.map +1 -0
- package/dist/lib/middlewares/route-module-jwt-validation-middleware.d.ts +4 -0
- package/dist/lib/middlewares/route-module-jwt-validation-middleware.d.ts.map +1 -0
- package/dist/lib/middlewares/route-module-jwt-validation-middleware.js +32 -0
- package/dist/lib/middlewares/route-module-jwt-validation-middleware.js.map +1 -0
- package/dist/lib/middlewares/route-module-schema-validation-middleware.d.ts +4 -0
- package/dist/lib/middlewares/route-module-schema-validation-middleware.d.ts.map +1 -0
- package/dist/lib/middlewares/route-module-schema-validation-middleware.js +72 -0
- package/dist/lib/middlewares/route-module-schema-validation-middleware.js.map +1 -0
- package/dist/lib/swagger-route-specification-generator.d.ts +78 -0
- package/dist/lib/swagger-route-specification-generator.d.ts.map +1 -0
- package/dist/lib/swagger-route-specification-generator.js +3 -0
- package/dist/lib/swagger-route-specification-generator.js.map +1 -0
- package/dist/lib/swagger-specification-types.d.ts +143 -0
- package/dist/lib/swagger-specification-types.d.ts.map +1 -0
- package/dist/lib/swagger-specification-types.js +3 -0
- package/dist/lib/swagger-specification-types.js.map +1 -0
- package/dist/lib/types-and-interfaces.d.ts +78 -0
- package/dist/lib/types-and-interfaces.d.ts.map +1 -0
- package/dist/lib/types-and-interfaces.js +3 -0
- package/dist/lib/types-and-interfaces.js.map +1 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +17 -0
- package/dist/lib/utils.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# AWS Lambda API Tools
|
|
2
|
+
|
|
3
|
+
A powerful toolkit for building enterprise-grade REST APIs with AWS Lambda and API Gateway (HTTP API). This package provides a structured approach to routing, middleware management, schema validation, and JWT authentication, with full TypeScript support.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
- 🛣️ **Structured Routing** - Define routes with complete type safety and automatic OpenAPI documentation generation
|
|
8
|
+
- 🔒 **JWT Authentication** - Built-in JWT validation middleware
|
|
9
|
+
- ✅ **Schema Validation** - Request/response validation using Joi
|
|
10
|
+
- 🚦 **Middleware Chain** - Flexible middleware system with type-safe middleware composition
|
|
11
|
+
- 📝 **OpenAPI/Swagger** - Automatic API documentation generation
|
|
12
|
+
- 🔍 **Type Safety** - Comprehensive TypeScript support
|
|
13
|
+
- 🎯 **Path Parameters** - Support for dynamic route parameters
|
|
14
|
+
- ⚡ **Performance** - Optimized for AWS Lambda execution
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```shell
|
|
19
|
+
npm install aws-lambda-api-tools
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### 1. Define Your Route Handlers
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// handlers/users/create-user.ts
|
|
28
|
+
import {
|
|
29
|
+
RouteModule,
|
|
30
|
+
RouteSchema,
|
|
31
|
+
jwtValidationMiddleware,
|
|
32
|
+
schemaValidationMiddleware,
|
|
33
|
+
} from 'aws-lambda-api-tools';
|
|
34
|
+
|
|
35
|
+
const routeSchema: RouteSchema = {
|
|
36
|
+
requestBody: CreateUserRequestSchema,
|
|
37
|
+
responseBody: CreateUserResponseSchema,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const handler = async (input: RouteArguments) => {
|
|
41
|
+
// Your handler logic here
|
|
42
|
+
return {
|
|
43
|
+
statusCode: 200,
|
|
44
|
+
body: { /* response data */ }
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
routeChain: [
|
|
50
|
+
jwtValidationMiddleware,
|
|
51
|
+
schemaValidationMiddleware(routeSchema),
|
|
52
|
+
handler
|
|
53
|
+
],
|
|
54
|
+
routeSchema,
|
|
55
|
+
} as RouteModule;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Configure Your Routes
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// routes/users.config.ts
|
|
62
|
+
import { ConfigRouteEntry } from 'aws-lambda-api-tools';
|
|
63
|
+
|
|
64
|
+
export default [
|
|
65
|
+
{
|
|
66
|
+
description: 'Create user',
|
|
67
|
+
swaggerMethodName: 'createUser',
|
|
68
|
+
generateOpenApiDocs: true,
|
|
69
|
+
handlerPath: 'handlers/users/create-user',
|
|
70
|
+
method: 'POST',
|
|
71
|
+
path: '/api/v1/users',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
description: 'Get user by ID',
|
|
75
|
+
swaggerMethodName: 'getUser',
|
|
76
|
+
generateOpenApiDocs: true,
|
|
77
|
+
handlerPath: 'handlers/users/get-user',
|
|
78
|
+
method: 'GET',
|
|
79
|
+
path: '/api/v1/users/{userId}',
|
|
80
|
+
}
|
|
81
|
+
] as Array<ConfigRouteEntry>;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 3. Create Your Lambda Handler
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// index.ts
|
|
88
|
+
import { lambdaRouteProxyEntryHandler } from 'aws-lambda-api-tools';
|
|
89
|
+
import { config } from './routes-config';
|
|
90
|
+
import { routeModules } from './route-modules';
|
|
91
|
+
|
|
92
|
+
export const handler = lambdaRouteProxyEntryHandler(config, routeModules);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Route Configuration
|
|
96
|
+
|
|
97
|
+
Routes are defined using the `ConfigRouteEntry` interface:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface ConfigRouteEntry {
|
|
101
|
+
description: string;
|
|
102
|
+
swaggerMethodName: string;
|
|
103
|
+
generateOpenApiDocs: boolean;
|
|
104
|
+
handlerPath: string;
|
|
105
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'ANY';
|
|
106
|
+
path: string;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Middleware
|
|
111
|
+
|
|
112
|
+
### Built-in Middleware
|
|
113
|
+
|
|
114
|
+
#### JWT Validation
|
|
115
|
+
```typescript
|
|
116
|
+
import { jwtValidationMiddleware } from 'aws-lambda-api-tools';
|
|
117
|
+
|
|
118
|
+
const routeModule: RouteModule = {
|
|
119
|
+
routeChain: [
|
|
120
|
+
jwtValidationMiddleware,
|
|
121
|
+
handler
|
|
122
|
+
]
|
|
123
|
+
};
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Schema Validation
|
|
127
|
+
```typescript
|
|
128
|
+
import { schemaValidationMiddleware } from 'aws-lambda-api-tools';
|
|
129
|
+
|
|
130
|
+
const schema: RouteSchema = {
|
|
131
|
+
requestBody: Joi.object({
|
|
132
|
+
name: Joi.string().required()
|
|
133
|
+
}),
|
|
134
|
+
responseBody: Joi.object({
|
|
135
|
+
id: Joi.string(),
|
|
136
|
+
name: Joi.string()
|
|
137
|
+
})
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const routeModule: RouteModule = {
|
|
141
|
+
routeChain: [
|
|
142
|
+
schemaValidationMiddleware(schema),
|
|
143
|
+
handler
|
|
144
|
+
],
|
|
145
|
+
routeSchema: schema
|
|
146
|
+
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Error Handling
|
|
150
|
+
|
|
151
|
+
The package includes a `CustomError` class for standardized error responses:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { CustomError } from 'aws-lambda-api-tools';
|
|
155
|
+
|
|
156
|
+
throw new CustomError('Resource not found', 404);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Type Definitions
|
|
160
|
+
|
|
161
|
+
Key TypeScript interfaces:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
interface RouteModule {
|
|
165
|
+
routeChain: MiddlewareChain;
|
|
166
|
+
routeSchema?: RouteSchema;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface RouteSchema {
|
|
170
|
+
requestBody?: joi.Schema;
|
|
171
|
+
responseBody?: joi.Schema;
|
|
172
|
+
query?: Record<string, joi.Schema>;
|
|
173
|
+
params?: Record<string, joi.Schema>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
interface RouteArguments {
|
|
177
|
+
body: any;
|
|
178
|
+
params: Record<string, string>;
|
|
179
|
+
query: Record<string, string>;
|
|
180
|
+
routeData: any;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Best Practices
|
|
185
|
+
|
|
186
|
+
1. **Organized Route Structure**
|
|
187
|
+
- Group routes by feature/resource
|
|
188
|
+
- Use consistent file naming conventions
|
|
189
|
+
- Separate route configs from handlers
|
|
190
|
+
|
|
191
|
+
2. **Type Safety**
|
|
192
|
+
- Define schemas for request/response validation
|
|
193
|
+
- Use TypeScript interfaces for route configurations
|
|
194
|
+
- Leverage middleware type definitions
|
|
195
|
+
|
|
196
|
+
3. **Error Handling**
|
|
197
|
+
- Use `CustomError` for consistent error responses
|
|
198
|
+
- Implement proper error middleware
|
|
199
|
+
- Handle edge cases appropriately
|
|
200
|
+
|
|
201
|
+
4. **Security**
|
|
202
|
+
- Always use JWT validation for protected routes
|
|
203
|
+
- Implement proper permission checks
|
|
204
|
+
- Validate all input data
|
|
205
|
+
|
|
206
|
+
## Contributing
|
|
207
|
+
|
|
208
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { BaseResponseObject, BaseRouteResponse, MiddlewareArgumentsInputFunction, MiddlewareChain, MiddlewareSchemaInputFunction, ResponseData, ResponseError, ResponseObject, RouteArguments, RouteModule, RouteResponse, RouteSchema, ConfigRouteEntry, RouteConfig, Permission, } from './lib/types-and-interfaces';
|
|
2
|
+
export { CustomError } from './lib/custom-error';
|
|
3
|
+
export { lambdaRouteProxyEntryHandler } from './lib/lambda-route-proxy-entry-handler';
|
|
4
|
+
export { lambdaRouteProxyPathNotFound } from './lib/lambda-route-proxy-path-not-found';
|
|
5
|
+
export { schemaValidationMiddleware } from './lib/middlewares/route-module-schema-validation-middleware';
|
|
6
|
+
export { jwtValidationMiddleware } from './lib/middlewares/route-module-jwt-validation-middleware';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,gCAAgC,EAChC,eAAe,EACf,6BAA6B,EAC7B,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,UAAU,GACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAEvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,6DAA6D,CAAC;AAEzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,0DAA0D,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jwtValidationMiddleware = exports.schemaValidationMiddleware = exports.lambdaRouteProxyPathNotFound = exports.lambdaRouteProxyEntryHandler = exports.CustomError = void 0;
|
|
4
|
+
var custom_error_1 = require("./lib/custom-error");
|
|
5
|
+
Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } });
|
|
6
|
+
var lambda_route_proxy_entry_handler_1 = require("./lib/lambda-route-proxy-entry-handler");
|
|
7
|
+
Object.defineProperty(exports, "lambdaRouteProxyEntryHandler", { enumerable: true, get: function () { return lambda_route_proxy_entry_handler_1.lambdaRouteProxyEntryHandler; } });
|
|
8
|
+
var lambda_route_proxy_path_not_found_1 = require("./lib/lambda-route-proxy-path-not-found");
|
|
9
|
+
Object.defineProperty(exports, "lambdaRouteProxyPathNotFound", { enumerable: true, get: function () { return lambda_route_proxy_path_not_found_1.lambdaRouteProxyPathNotFound; } });
|
|
10
|
+
var route_module_schema_validation_middleware_1 = require("./lib/middlewares/route-module-schema-validation-middleware");
|
|
11
|
+
Object.defineProperty(exports, "schemaValidationMiddleware", { enumerable: true, get: function () { return route_module_schema_validation_middleware_1.schemaValidationMiddleware; } });
|
|
12
|
+
var route_module_jwt_validation_middleware_1 = require("./lib/middlewares/route-module-jwt-validation-middleware");
|
|
13
|
+
Object.defineProperty(exports, "jwtValidationMiddleware", { enumerable: true, get: function () { return route_module_jwt_validation_middleware_1.jwtValidationMiddleware; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAkBA,mDAAiD;AAAxC,2GAAA,WAAW,OAAA;AAEpB,2FAAsF;AAA7E,gJAAA,4BAA4B,OAAA;AAErC,6FAAuF;AAA9E,iJAAA,4BAA4B,OAAA;AAErC,yHAAyG;AAAhG,uJAAA,0BAA0B,OAAA;AAEnC,mHAAmG;AAA1F,iJAAA,uBAAuB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-helper.d.ts","sourceRoot":"","sources":["../../src/lib/authorization-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,eAAO,MAAM,cAAc,yCAO1B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authorizeRoute = void 0;
|
|
4
|
+
// import { CustomError } from './custom-error';
|
|
5
|
+
const authorizeRoute = (event) => {
|
|
6
|
+
// extract token
|
|
7
|
+
const token = event.headers.authorization;
|
|
8
|
+
if (!token) {
|
|
9
|
+
// throw new CustomError('Request is unauthenticated. No bearer token exists.', 401);
|
|
10
|
+
}
|
|
11
|
+
// implement authorize check with jwt from issuer
|
|
12
|
+
};
|
|
13
|
+
exports.authorizeRoute = authorizeRoute;
|
|
14
|
+
//# sourceMappingURL=authorization-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-helper.js","sourceRoot":"","sources":["../../src/lib/authorization-helper.ts"],"names":[],"mappings":";;;AACA,gDAAgD;AAEzC,MAAM,cAAc,GAAG,CAAC,KAA6B,EAAE,EAAE;IAC9D,gBAAgB;IAChB,MAAM,KAAK,GAAW,KAAK,CAAC,OAAQ,CAAC,aAAuB,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE;QACV,qFAAqF;KACtF;IACD,iDAAiD;AACnD,CAAC,CAAC;AAPW,QAAA,cAAc,kBAOzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-error.d.ts","sourceRoot":"","sources":["../../src/lib/custom-error.ts"],"names":[],"mappings":"AACA,qBAAa,WAAY,SAAQ,KAAK;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;gBAEL,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAM/C,IAAI,cAAc,WAEjB;IAED,IAAa,OAAO,WAEnB;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomError = void 0;
|
|
4
|
+
class CustomError extends Error {
|
|
5
|
+
constructor(message, statusCode) {
|
|
6
|
+
super(message);
|
|
7
|
+
this._httpStatusCode = statusCode || 500;
|
|
8
|
+
this._message = message;
|
|
9
|
+
}
|
|
10
|
+
get httpStatusCode() {
|
|
11
|
+
return this._httpStatusCode;
|
|
12
|
+
}
|
|
13
|
+
get message() {
|
|
14
|
+
return this._message;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.CustomError = CustomError;
|
|
18
|
+
;
|
|
19
|
+
//# sourceMappingURL=custom-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../src/lib/custom-error.ts"],"names":[],"mappings":";;;AACA,MAAa,WAAY,SAAQ,KAAK;IAIpC,YAAY,OAAe,EAAE,UAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,eAAe,GAAG,UAAU,IAAI,GAAG,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,IAAa,OAAO;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAjBD,kCAiBC;AAAA,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { APIGatewayProxyEventV2 } from 'aws-lambda';
|
|
2
|
+
import { RouteConfig, RouteArguments, RouteModule } from './types-and-interfaces';
|
|
3
|
+
export declare const getRouteModule: (config: RouteConfig, method: string, path: string, availableRouteModules: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}) => RouteModule;
|
|
6
|
+
export declare const getRouteModuleResult: ({ routeChain }: RouteModule, incoming: RouteArguments) => Promise<any>;
|
|
7
|
+
export declare const lambdaRouteProxyEntryHandler: (config: RouteConfig, availableRouteModules: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}) => (event: APIGatewayProxyEventV2) => Promise<{}>;
|
|
10
|
+
//# sourceMappingURL=lambda-route-proxy-entry-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-route-proxy-entry-handler.d.ts","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-entry-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAoB,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAYpG,eAAO,MAAM,cAAc,WAAY,WAAW,UAAU,MAAM,QAAQ,MAAM;;MAAkD,WAUjI,CAAC;AAEF,eAAO,MAAM,oBAAoB,mBAA0B,WAAW,YAAY,cAAc,KAAG,QAAQ,GAAG,CAM7G,CAAC;AAEF,eAAO,MAAM,4BAA4B,WAAY,WAAW;;oDAuC7D,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lambdaRouteProxyEntryHandler = exports.getRouteModuleResult = exports.getRouteModule = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
const authorization_helper_1 = require("./authorization-helper");
|
|
6
|
+
const getRouteConfigEntry = (config, method, path) => config.routes.find(r => r.path.toLowerCase() === path.toLowerCase() && r.method.toLowerCase() === method.toLowerCase());
|
|
7
|
+
const shouldAuthorizeRoute = (routesConfig, routeConfigEntry) => (routesConfig.authorizeAllRoutes && routeConfigEntry.authorizeRoute !== false)
|
|
8
|
+
||
|
|
9
|
+
routeConfigEntry.authorizeRoute === true;
|
|
10
|
+
const getRouteModule = (config, method, path, availableRouteModules) => {
|
|
11
|
+
const routeEntry = getRouteConfigEntry(config, method, path);
|
|
12
|
+
let routeModule = null;
|
|
13
|
+
console.log(`route entry: ${JSON.stringify(routeEntry)}`);
|
|
14
|
+
if (routeEntry) {
|
|
15
|
+
const matchingRouteModuleMapKey = Object.keys(availableRouteModules).find((k) => routeEntry.handlerPath.endsWith(k));
|
|
16
|
+
// routeModule = availableRouteModules[routeEntry.handlerPath.split('/').reverse()[0]];
|
|
17
|
+
routeModule = availableRouteModules[matchingRouteModuleMapKey];
|
|
18
|
+
}
|
|
19
|
+
return routeModule;
|
|
20
|
+
};
|
|
21
|
+
exports.getRouteModule = getRouteModule;
|
|
22
|
+
const getRouteModuleResult = async ({ routeChain }, incoming) => {
|
|
23
|
+
let returnValue = incoming;
|
|
24
|
+
for (const chainFn of routeChain) {
|
|
25
|
+
returnValue = await chainFn(returnValue);
|
|
26
|
+
}
|
|
27
|
+
return returnValue;
|
|
28
|
+
};
|
|
29
|
+
exports.getRouteModuleResult = getRouteModuleResult;
|
|
30
|
+
const lambdaRouteProxyEntryHandler = (config, availableRouteModules) => async (event) => {
|
|
31
|
+
console.log(`Event Data: ${JSON.stringify(event)}`);
|
|
32
|
+
const { routeKey, queryStringParameters, pathParameters, body, } = event;
|
|
33
|
+
let retVal = {};
|
|
34
|
+
try {
|
|
35
|
+
const [method, path] = routeKey.split(' ');
|
|
36
|
+
if (shouldAuthorizeRoute(config, getRouteConfigEntry(config, method, path))) {
|
|
37
|
+
await (0, authorization_helper_1.authorizeRoute)(event);
|
|
38
|
+
}
|
|
39
|
+
const routeModule = (0, exports.getRouteModule)(config, method, path, availableRouteModules);
|
|
40
|
+
retVal = await (0, exports.getRouteModuleResult)(routeModule, {
|
|
41
|
+
query: queryStringParameters,
|
|
42
|
+
params: pathParameters,
|
|
43
|
+
body: body ? JSON.parse(body) : undefined,
|
|
44
|
+
rawEvent: event,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error(JSON.stringify({ error, stack: error.stack }));
|
|
49
|
+
if (error instanceof custom_error_1.CustomError) {
|
|
50
|
+
retVal = {
|
|
51
|
+
statusCode: error.httpStatusCode,
|
|
52
|
+
headers: { 'Content-Type': 'application/json' },
|
|
53
|
+
body: error.message,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
retVal = {
|
|
58
|
+
statusCode: 500,
|
|
59
|
+
headers: { 'Content-Type': 'application/json' },
|
|
60
|
+
body: error.message || JSON.stringify(error),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return retVal;
|
|
65
|
+
};
|
|
66
|
+
exports.lambdaRouteProxyEntryHandler = lambdaRouteProxyEntryHandler;
|
|
67
|
+
//# sourceMappingURL=lambda-route-proxy-entry-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-route-proxy-entry-handler.js","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-entry-handler.ts"],"names":[],"mappings":";;;AAEA,iDAA6C;AAE7C,iEAAwD;AAExD,MAAM,mBAAmB,GAAG,CAAC,MAAmB,EAAE,MA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,IAAI,KAAK,YAAY,0BAAW,EAAE;YAChC,MAAM,GAAG;gBACP,UAAU,EAAE,KAAK,CAAC,cAAc;gBAChC,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,IAAI,EAAE,KAAK,CAAC,OAAO;aACpB,CAAC;SACH;aAAM;YACL,MAAM,GAAG;gBACP,UAAU,EAAE,GAAG;gBACf,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;aAC7C,CAAC;SACH;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAvCS,QAAA,4BAA4B,gCAuCrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-route-proxy-path-not-found.d.ts","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-path-not-found.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAsBhC,eAAO,MAAM,4BAA4B,EAAE,WAG1C,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lambdaRouteProxyPathNotFound = void 0;
|
|
4
|
+
const handler = async (input) => {
|
|
5
|
+
console.log('--- NOT FOUND HANDLER ---');
|
|
6
|
+
console.log(input.rawEvent.requestContext.http.method);
|
|
7
|
+
if (input.rawEvent.requestContext.http.method === 'OPTIONS') {
|
|
8
|
+
return {
|
|
9
|
+
statusCode: 200,
|
|
10
|
+
headers: {
|
|
11
|
+
'Access-Control-Allow-Origin': '*',
|
|
12
|
+
'Access-Control-Allow-Methods': '*',
|
|
13
|
+
'Access-Control-Allow-Headers': '*',
|
|
14
|
+
'Access-Control-Max-Age': 300,
|
|
15
|
+
'Access-Control-Expose-Headers': 'Access-Control-Allow-Origin',
|
|
16
|
+
'Access-Control-Allow-Credentials': true,
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return { statusCode: 404, body: JSON.stringify('Not found') };
|
|
22
|
+
};
|
|
23
|
+
exports.lambdaRouteProxyPathNotFound = {
|
|
24
|
+
routeChain: [handler],
|
|
25
|
+
routeSchema: {},
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=lambda-route-proxy-path-not-found.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-route-proxy-path-not-found.js","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-path-not-found.ts"],"names":[],"mappings":";;;AAKA,MAAM,OAAO,GAAG,KAAK,EAAE,KAAqB,EAAgB,EAAE;IAC5D,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxD,IAAI,KAAK,CAAC,QAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;QAC5D,OAAO;YACL,UAAU,EAAE,GAAG;YACf,OAAO,EAAE;gBACP,6BAA6B,EAAE,GAAG;gBAClC,8BAA8B,EAAE,GAAG;gBACnC,8BAA8B,EAAE,GAAG;gBACnC,wBAAwB,EAAE,GAAG;gBAC7B,+BAA+B,EAAE,6BAA6B;gBAC9D,kCAAkC,EAAE,IAAI;gBACxC,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC;KACH;IACD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;AAChE,CAAC,CAAC;AAEW,QAAA,4BAA4B,GAAgB;IACvD,UAAU,EAAE,CAAC,OAAO,CAAC;IACrB,WAAW,EAAE,EAAE;CAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-module-jwt-validation-middleware.d.ts","sourceRoot":"","sources":["../../../src/lib/middlewares/route-module-jwt-validation-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAIzD,eAAO,MAAM,uBAAuB,iBAAkB,cAAc,KAAG,cAuBtE,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jwtValidationMiddleware = void 0;
|
|
4
|
+
const custom_error_1 = require("../custom-error");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const jwtValidationMiddleware = (incomingData) => {
|
|
7
|
+
const { routeData = {} } = incomingData;
|
|
8
|
+
const authHeader = incomingData.rawEvent.headers['authorization'];
|
|
9
|
+
if (!authHeader) {
|
|
10
|
+
throw new custom_error_1.CustomError('No authorization header provided.', 401);
|
|
11
|
+
}
|
|
12
|
+
const tokenString = authHeader.replace('Bearer ', '');
|
|
13
|
+
const jwt = (0, utils_1.parseJwt)(tokenString);
|
|
14
|
+
console.log(`Decoded token: ${JSON.stringify(jwt)}`);
|
|
15
|
+
if (!jwt) {
|
|
16
|
+
throw new custom_error_1.CustomError('Token not valid.', 401);
|
|
17
|
+
}
|
|
18
|
+
if (!jwt.email_verified) {
|
|
19
|
+
throw new custom_error_1.CustomError('Email for this account has not been verified.', 401);
|
|
20
|
+
}
|
|
21
|
+
if ((jwt.exp * 1000) < Date.now()) {
|
|
22
|
+
throw new custom_error_1.CustomError('Session token is expired.', 403);
|
|
23
|
+
}
|
|
24
|
+
if (!jwt || !(jwt.email && jwt.email_verified)) {
|
|
25
|
+
throw new custom_error_1.CustomError('Token not valid.', 401);
|
|
26
|
+
}
|
|
27
|
+
routeData.jwt = jwt;
|
|
28
|
+
return { ...incomingData, routeData };
|
|
29
|
+
};
|
|
30
|
+
exports.jwtValidationMiddleware = jwtValidationMiddleware;
|
|
31
|
+
exports.default = exports.jwtValidationMiddleware;
|
|
32
|
+
//# sourceMappingURL=route-module-jwt-validation-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-module-jwt-validation-middleware.js","sourceRoot":"","sources":["../../../src/lib/middlewares/route-module-jwt-validation-middleware.ts"],"names":[],"mappings":";;;AACA,kDAA8C;AAC9C,oCAAoC;AAE7B,MAAM,uBAAuB,GAAG,CAAC,YAA4B,EAAkB,EAAE;IACtF,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,YAAY,CAAC;IACxC,MAAM,UAAU,GAAG,YAAY,CAAC,QAAS,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACnE,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,0BAAW,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;KACjE;IACD,MAAM,WAAW,GAAG,UAAW,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,IAAA,gBAAQ,EAAC,WAAW,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrD,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,0BAAW,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;KAChD;IACD,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE;QACvB,MAAM,IAAI,0BAAW,CAAC,+CAA+C,EAAE,GAAG,CAAC,CAAC;KAC7E;IACD,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE;QACjC,MAAM,IAAI,0BAAW,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;KACzD;IACD,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,cAAc,CAAC,EAAE;QAC9C,MAAM,IAAI,0BAAW,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;KAChD;IACD,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC;IACpB,OAAO,EAAE,GAAG,YAAY,EAAE,SAAS,EAAE,CAAC;AACxC,CAAC,CAAC;AAvBW,QAAA,uBAAuB,2BAuBlC;AAEF,kBAAe,+BAAuB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RouteArguments, RouteSchema } from '../types-and-interfaces';
|
|
2
|
+
export declare const schemaValidationMiddleware: (routeSchema: RouteSchema) => (incomingData: RouteArguments) => RouteArguments;
|
|
3
|
+
export default schemaValidationMiddleware;
|
|
4
|
+
//# sourceMappingURL=route-module-schema-validation-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-module-schema-validation-middleware.d.ts","sourceRoot":"","sources":["../../../src/lib/middlewares/route-module-schema-validation-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtE,eAAO,MAAM,0BAA0B,gBAAiB,WAAW,oBAAoB,cAAc,KAAG,cAwDvG,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.schemaValidationMiddleware = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const custom_error_1 = require("../custom-error");
|
|
9
|
+
const schemaValidationMiddleware = (routeSchema) => (incomingData) => {
|
|
10
|
+
console.log(JSON.stringify(incomingData));
|
|
11
|
+
let { params, body, query, ...rest } = incomingData;
|
|
12
|
+
params = params || {};
|
|
13
|
+
body = body || {};
|
|
14
|
+
query = query || {};
|
|
15
|
+
const { params: sParams, requestBody: sBody, query: sQuery } = routeSchema;
|
|
16
|
+
const validatedOutput = {};
|
|
17
|
+
const errorMap = {
|
|
18
|
+
params: [],
|
|
19
|
+
body: [],
|
|
20
|
+
query: [],
|
|
21
|
+
};
|
|
22
|
+
if (sParams) {
|
|
23
|
+
console.log(`params schema: ${JSON.stringify(sParams)}`);
|
|
24
|
+
console.log(`params data: ${JSON.stringify(params)}`);
|
|
25
|
+
try {
|
|
26
|
+
validatedOutput.params = joi_1.default.attempt(params, joi_1.default.compile(sParams), { abortEarly: false });
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.error(`sParams Error: ${JSON.stringify(err)}`);
|
|
30
|
+
errorMap.params.push(...err.details.map((d) => d.message));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (sBody) {
|
|
34
|
+
console.log(`body schema: ${JSON.stringify(sBody)}`);
|
|
35
|
+
console.log(`body data: ${JSON.stringify(body)}`);
|
|
36
|
+
try {
|
|
37
|
+
validatedOutput.body = joi_1.default.attempt(body, joi_1.default.compile(sBody), { allowUnknown: true, abortEarly: false });
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error(`sBody Error: ${JSON.stringify(err)}`);
|
|
41
|
+
errorMap.body.push(...err.details.map((d) => d.message));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (sQuery) {
|
|
45
|
+
console.log(`query schema: ${JSON.stringify(sQuery)}`);
|
|
46
|
+
console.log(`query data: ${JSON.stringify(query)}`);
|
|
47
|
+
try {
|
|
48
|
+
validatedOutput.query = joi_1.default.attempt(query, joi_1.default.compile(sQuery), { abortEarly: false });
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.error(`sQuery Error: ${JSON.stringify(err)}`);
|
|
52
|
+
errorMap.query.push(...err.details.map((d) => d.message));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (errorMap.body.length || errorMap.params.length || errorMap.query.length) {
|
|
56
|
+
const validationErrorMessage = `The request contains validation errors.
|
|
57
|
+
${errorMap.params.length ? 'Path Parameters:\n' + errorMap.params.join('\n') : ''}
|
|
58
|
+
${errorMap.query.length ? 'Querystring Parameters:\n' + errorMap.query.join('\n') : ''}
|
|
59
|
+
${errorMap.body.length ? 'Request Body:\n' + errorMap.body.join('\n') : ''}
|
|
60
|
+
`;
|
|
61
|
+
throw new custom_error_1.CustomError(validationErrorMessage, 400);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return {
|
|
65
|
+
...validatedOutput,
|
|
66
|
+
...rest,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.schemaValidationMiddleware = schemaValidationMiddleware;
|
|
71
|
+
exports.default = exports.schemaValidationMiddleware;
|
|
72
|
+
//# sourceMappingURL=route-module-schema-validation-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-module-schema-validation-middleware.js","sourceRoot":"","sources":["../../../src/lib/middlewares/route-module-schema-validation-middleware.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AAEtB,kDAA8C;AAEvC,MAAM,0BAA0B,GAAG,CAAC,WAAwB,EAAE,EAAE,CAAC,CAAC,YAA4B,EAAkB,EAAE;IACvH,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IAC1C,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,YAAY,CAAC;IACpD,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IACtB,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAClB,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAA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IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;MAC/E,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,2BAA2B,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;MACpF,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;KACzE,CAAC;QACF,MAAM,IAAI,0BAAW,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;KACpD;SAAM;QACL,OAAO;YACL,GAAG,eAAe;YAClB,GAAG,IAAI;SACR,CAAC;KACH;AACH,CAAC,CAAC;AAxDW,QAAA,0BAA0B,8BAwDrC;AAEF,kBAAe,kCAA0B,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { APIGatewayProxyEventV2 } from 'aws-lambda';
|
|
2
|
+
import { Schema } from 'joi';
|
|
3
|
+
import * as swaggerTypes from './swagger-specification-types';
|
|
4
|
+
export type ConfigRouteEntry = {
|
|
5
|
+
functionName?: string;
|
|
6
|
+
description: string;
|
|
7
|
+
swaggerMethodName?: string;
|
|
8
|
+
path: string;
|
|
9
|
+
method: 'ANY' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT';
|
|
10
|
+
generateOpenApiDocs: boolean;
|
|
11
|
+
handlerPath: string;
|
|
12
|
+
authorizeRoute?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type RouteConfig = {
|
|
15
|
+
authorizeAllRoutes?: boolean;
|
|
16
|
+
routes: Array<ConfigRouteEntry>;
|
|
17
|
+
};
|
|
18
|
+
export type RouteArguments = {
|
|
19
|
+
params?: any;
|
|
20
|
+
body?: any;
|
|
21
|
+
query?: any;
|
|
22
|
+
form?: any;
|
|
23
|
+
rawEvent?: APIGatewayProxyEventV2;
|
|
24
|
+
routeData?: any;
|
|
25
|
+
};
|
|
26
|
+
export interface RouteSchema {
|
|
27
|
+
params?: {
|
|
28
|
+
[key: string]: Schema<any>;
|
|
29
|
+
};
|
|
30
|
+
query?: {
|
|
31
|
+
[key: string]: Schema<any>;
|
|
32
|
+
};
|
|
33
|
+
form?: {
|
|
34
|
+
[key: string]: Schema<any>;
|
|
35
|
+
};
|
|
36
|
+
requestBody?: Schema<any> | {
|
|
37
|
+
[key: string]: Schema<any>;
|
|
38
|
+
};
|
|
39
|
+
responseBody?: Schema<any> | {
|
|
40
|
+
[key: string]: Schema<any>;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface BaseResponseObject extends swaggerTypes.ResponseObject {
|
|
44
|
+
}
|
|
45
|
+
export interface ResponseError extends swaggerTypes.ResponseObject {
|
|
46
|
+
error: {
|
|
47
|
+
statusCode: string;
|
|
48
|
+
message: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface ResponseData extends swaggerTypes.ResponseObject {
|
|
52
|
+
data: any;
|
|
53
|
+
}
|
|
54
|
+
export type ResponseObject<T> = ResponseData | ResponseError;
|
|
55
|
+
export type BaseRouteResponse<T> = {
|
|
56
|
+
[key in '201' | '202' | '203' | '204' | '205' | '206' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '419']: ResponseObject<T>;
|
|
57
|
+
};
|
|
58
|
+
export interface RouteResponse<T> extends BaseRouteResponse<T> {
|
|
59
|
+
'200': ResponseObject<T>;
|
|
60
|
+
}
|
|
61
|
+
export type MiddlewareSchemaInputFunction = (input: RouteSchema) => RouteArguments;
|
|
62
|
+
export type MiddlewareArgumentsInputFunction = (input: RouteArguments) => any;
|
|
63
|
+
export type MiddlewareChain = Array<MiddlewareArgumentsInputFunction>;
|
|
64
|
+
export type RouteModule = {
|
|
65
|
+
routeChain: MiddlewareChain;
|
|
66
|
+
routeSchema: RouteSchema;
|
|
67
|
+
};
|
|
68
|
+
export interface Permission {
|
|
69
|
+
id: string;
|
|
70
|
+
systemPermission: string;
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
humanReadableName: string;
|
|
73
|
+
entity: {
|
|
74
|
+
level: string;
|
|
75
|
+
humanReadableName: string;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=swagger-route-specification-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-route-specification-generator.d.ts","sourceRoot":"","sources":["../../src/lib/swagger-route-specification-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,YAAY,MAAM,+BAA+B,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IACjF,mBAAmB,EAAE,OAAO,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,MAAM,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CA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L,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC5D,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED,MAAM,MAAM,6BAA6B,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,cAAc,CAAC;AACnF,MAAM,MAAM,gCAAgC,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,GAAG,CAAC;AAC9E,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,gCAAgC,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,eAAe,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-route-specification-generator.js","sourceRoot":"","sources":["../../src/lib/swagger-route-specification-generator.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { URL } from 'url';
|
|
3
|
+
export interface OpenAPI2 {
|
|
4
|
+
swagger: string;
|
|
5
|
+
paths?: Record<string, PathItemObject>;
|
|
6
|
+
definitions?: Record<string, SchemaObject>;
|
|
7
|
+
parameters?: ParameterObject[];
|
|
8
|
+
responses?: Record<string, ResponseObject>;
|
|
9
|
+
}
|
|
10
|
+
export interface OpenAPI3 {
|
|
11
|
+
openapi: string;
|
|
12
|
+
paths?: Record<string, PathItemObject>;
|
|
13
|
+
components?: {
|
|
14
|
+
schemas?: Record<string, ReferenceObject | SchemaObject>;
|
|
15
|
+
responses?: Record<string, ReferenceObject | ResponseObject>;
|
|
16
|
+
parameters?: Record<string, ReferenceObject | ParameterObject>;
|
|
17
|
+
requestBodies?: Record<string, ReferenceObject | RequestBody>;
|
|
18
|
+
headers?: Record<string, ReferenceObject | HeaderObject>;
|
|
19
|
+
links?: Record<string, ReferenceObject | LinkObject>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface HeaderObject {
|
|
23
|
+
type?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
required?: boolean;
|
|
26
|
+
schema: ReferenceObject | SchemaObject;
|
|
27
|
+
}
|
|
28
|
+
export interface PathItemObject {
|
|
29
|
+
$ref?: string;
|
|
30
|
+
summary?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
get?: OperationObject;
|
|
33
|
+
put?: OperationObject;
|
|
34
|
+
post?: OperationObject;
|
|
35
|
+
delete?: OperationObject;
|
|
36
|
+
options?: OperationObject;
|
|
37
|
+
head?: OperationObject;
|
|
38
|
+
patch?: OperationObject;
|
|
39
|
+
trace?: OperationObject;
|
|
40
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
41
|
+
}
|
|
42
|
+
export interface LinkObject {
|
|
43
|
+
operationRef?: string;
|
|
44
|
+
operationId?: string;
|
|
45
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
46
|
+
requestBody?: RequestBody;
|
|
47
|
+
description?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface OperationObject {
|
|
50
|
+
description?: string;
|
|
51
|
+
tags?: string[];
|
|
52
|
+
summary?: string;
|
|
53
|
+
operationId?: string;
|
|
54
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
55
|
+
requestBody?: ReferenceObject | RequestBody;
|
|
56
|
+
responses?: Record<string, ReferenceObject | ResponseObject>;
|
|
57
|
+
}
|
|
58
|
+
export interface ParameterObject {
|
|
59
|
+
name?: string;
|
|
60
|
+
in?: "query" | "header" | "path" | /* V3 */ "cookie" | /* V2 */ "formData" | /* V2 */ "body";
|
|
61
|
+
description?: string;
|
|
62
|
+
required?: boolean;
|
|
63
|
+
deprecated?: boolean;
|
|
64
|
+
schema?: ReferenceObject | SchemaObject;
|
|
65
|
+
type?: "string" | "number" | "integer" | "boolean" | "array" | "file";
|
|
66
|
+
items?: ReferenceObject | SchemaObject;
|
|
67
|
+
enum?: string[];
|
|
68
|
+
}
|
|
69
|
+
export type ReferenceObject = {
|
|
70
|
+
$ref: string;
|
|
71
|
+
};
|
|
72
|
+
export interface ResponseObject {
|
|
73
|
+
description?: string;
|
|
74
|
+
headers?: Record<string, ReferenceObject | HeaderObject>;
|
|
75
|
+
schema?: ReferenceObject | SchemaObject;
|
|
76
|
+
links?: Record<string, ReferenceObject | LinkObject>;
|
|
77
|
+
content?: {
|
|
78
|
+
[contentType: string]: {
|
|
79
|
+
schema: ReferenceObject | SchemaObject;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export interface RequestBody {
|
|
84
|
+
description?: string;
|
|
85
|
+
content?: {
|
|
86
|
+
[contentType: string]: {
|
|
87
|
+
schema: ReferenceObject | SchemaObject;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export interface SchemaObject {
|
|
92
|
+
title?: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
required?: string[];
|
|
95
|
+
enum?: string[];
|
|
96
|
+
type?: string;
|
|
97
|
+
items?: ReferenceObject | SchemaObject;
|
|
98
|
+
allOf?: SchemaObject;
|
|
99
|
+
properties?: Record<string, ReferenceObject | SchemaObject>;
|
|
100
|
+
default?: any;
|
|
101
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
102
|
+
nullable?: boolean;
|
|
103
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
104
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
105
|
+
format?: string;
|
|
106
|
+
}
|
|
107
|
+
export type SchemaFormatter = (schemaObj: SchemaObject) => string | undefined;
|
|
108
|
+
export interface SwaggerToTSOptions {
|
|
109
|
+
/** Allow arbitrary properties on schemas (default: false) */
|
|
110
|
+
additionalProperties?: boolean;
|
|
111
|
+
/** (optional) Specify auth if using openapi-typescript to fetch URL */
|
|
112
|
+
auth?: string;
|
|
113
|
+
/** (optional) Specify current working directory (cwd) to resolve remote schemas on disk (not needed for remote URL schemas) */
|
|
114
|
+
cwd?: URL;
|
|
115
|
+
/** Specify a formatter */
|
|
116
|
+
formatter?: SchemaFormatter;
|
|
117
|
+
/** Generates immutable types (readonly properties and readonly array) */
|
|
118
|
+
immutableTypes?: boolean;
|
|
119
|
+
/** (optional) Treat schema objects with default values as non-nullable */
|
|
120
|
+
defaultNonNullable?: boolean;
|
|
121
|
+
/** (optional) Path to Prettier config */
|
|
122
|
+
prettierConfig?: string;
|
|
123
|
+
/** (optional) Parsing input document as raw schema rather than OpenAPI document */
|
|
124
|
+
rawSchema?: boolean;
|
|
125
|
+
/** (optional) Should logging be suppressed? (necessary for STDOUT) */
|
|
126
|
+
silent?: boolean;
|
|
127
|
+
/** (optional) OpenAPI version. Must be present if parsing raw schema */
|
|
128
|
+
version?: number;
|
|
129
|
+
}
|
|
130
|
+
/** Context passed to all submodules */
|
|
131
|
+
export interface GlobalContext {
|
|
132
|
+
additionalProperties: boolean;
|
|
133
|
+
auth?: string;
|
|
134
|
+
formatter?: SchemaFormatter;
|
|
135
|
+
immutableTypes: boolean;
|
|
136
|
+
defaultNonNullable: boolean;
|
|
137
|
+
/** (optional) Should logging be suppressed? (necessary for STDOUT) */
|
|
138
|
+
silent?: boolean;
|
|
139
|
+
namespace?: string;
|
|
140
|
+
rawSchema: boolean;
|
|
141
|
+
version: number;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=swagger-specification-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-specification-types.d.ts","sourceRoot":"","sources":["../../src/lib/swagger-specification-types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC3C,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE;QACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,YAAY,CAAC,CAAC;QACzD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,cAAc,CAAC,CAAC;QAC7D,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAAC,CAAC;QAC/D,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC,CAAC;QAC9D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,YAAY,CAAC,CAAC;QACzD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,UAAU,CAAC,CAAC;KACtD,CAAC;CACH;AAED,MAAM,WAAW,YA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IACpB,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,uCAAuC;AACvC,MAAM,WAAW,aAAa;IAC5B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-specification-types.js","sourceRoot":"","sources":["../../src/lib/swagger-specification-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { APIGatewayProxyEventV2 } from 'aws-lambda';
|
|
2
|
+
import { Schema } from 'joi';
|
|
3
|
+
import * as swaggerTypes from './swagger-specification-types';
|
|
4
|
+
export type ConfigRouteEntry = {
|
|
5
|
+
functionName?: string;
|
|
6
|
+
description: string;
|
|
7
|
+
swaggerMethodName?: string;
|
|
8
|
+
path: string;
|
|
9
|
+
method: 'ANY' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT';
|
|
10
|
+
generateOpenApiDocs: boolean;
|
|
11
|
+
handlerPath: string;
|
|
12
|
+
authorizeRoute?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type RouteConfig = {
|
|
15
|
+
authorizeAllRoutes?: boolean;
|
|
16
|
+
routes: Array<ConfigRouteEntry>;
|
|
17
|
+
};
|
|
18
|
+
export type RouteArguments = {
|
|
19
|
+
params?: any;
|
|
20
|
+
body?: any;
|
|
21
|
+
query?: any;
|
|
22
|
+
form?: any;
|
|
23
|
+
rawEvent?: APIGatewayProxyEventV2;
|
|
24
|
+
routeData?: any;
|
|
25
|
+
};
|
|
26
|
+
export interface RouteSchema {
|
|
27
|
+
params?: {
|
|
28
|
+
[key: string]: Schema<any>;
|
|
29
|
+
};
|
|
30
|
+
query?: {
|
|
31
|
+
[key: string]: Schema<any>;
|
|
32
|
+
};
|
|
33
|
+
form?: {
|
|
34
|
+
[key: string]: Schema<any>;
|
|
35
|
+
};
|
|
36
|
+
requestBody?: Schema<any> | {
|
|
37
|
+
[key: string]: Schema<any>;
|
|
38
|
+
};
|
|
39
|
+
responseBody?: Schema<any> | {
|
|
40
|
+
[key: string]: Schema<any>;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface BaseResponseObject extends swaggerTypes.ResponseObject {
|
|
44
|
+
}
|
|
45
|
+
export interface ResponseError extends swaggerTypes.ResponseObject {
|
|
46
|
+
error: {
|
|
47
|
+
statusCode: string;
|
|
48
|
+
message: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface ResponseData extends swaggerTypes.ResponseObject {
|
|
52
|
+
data: any;
|
|
53
|
+
}
|
|
54
|
+
export type ResponseObject<T> = ResponseData | ResponseError;
|
|
55
|
+
export type BaseRouteResponse<T> = {
|
|
56
|
+
[key in '201' | '202' | '203' | '204' | '205' | '206' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '419']: ResponseObject<T>;
|
|
57
|
+
};
|
|
58
|
+
export interface RouteResponse<T> extends BaseRouteResponse<T> {
|
|
59
|
+
'200': ResponseObject<T>;
|
|
60
|
+
}
|
|
61
|
+
export type MiddlewareSchemaInputFunction = (input: RouteSchema) => RouteArguments;
|
|
62
|
+
export type MiddlewareArgumentsInputFunction = (input: RouteArguments) => any;
|
|
63
|
+
export type MiddlewareChain = Array<MiddlewareArgumentsInputFunction>;
|
|
64
|
+
export type RouteModule = {
|
|
65
|
+
routeChain: MiddlewareChain;
|
|
66
|
+
routeSchema: RouteSchema;
|
|
67
|
+
};
|
|
68
|
+
export interface Permission {
|
|
69
|
+
id: string;
|
|
70
|
+
systemPermission: string;
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
humanReadableName: string;
|
|
73
|
+
entity: {
|
|
74
|
+
level: string;
|
|
75
|
+
humanReadableName: string;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=types-and-interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-and-interfaces.d.ts","sourceRoot":"","sources":["../../src/lib/types-and-interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,YAAY,MAAM,+BAA+B,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IACjF,mBAAmB,EAAE,OAAO,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,MAAM,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,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K,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC5D,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED,MAAM,MAAM,6BAA6B,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,cAAc,CAAC;AACnF,MAAM,MAAM,gCAAgC,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,GAAG,CAAC;AAC9E,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,gCAAgC,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,eAAe,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-and-interfaces.js","sourceRoot":"","sources":["../../src/lib/types-and-interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,UAAW,MAAM,QAQrC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseJwt = void 0;
|
|
7
|
+
const atob_1 = __importDefault(require("atob"));
|
|
8
|
+
const parseJwt = (token) => {
|
|
9
|
+
var base64Url = token.includes('.') ? token.split('.')[1] : token;
|
|
10
|
+
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
11
|
+
var jsonPayload = decodeURIComponent((0, atob_1.default)(base64).split('').map(function (c) {
|
|
12
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
13
|
+
}).join(''));
|
|
14
|
+
return JSON.parse(jsonPayload);
|
|
15
|
+
};
|
|
16
|
+
exports.parseJwt = parseJwt;
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuC;AAEhC,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,EAAE;IACxC,IAAI,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,IAAI,MAAM,GAAG,SAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC9D,IAAI,WAAW,GAAG,kBAAkB,CAAC,IAAA,cAAI,EAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,UAAS,CAAS;QAC9E,OAAO,GAAG,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAEb,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC,CAAC;AARW,QAAA,QAAQ,YAQnB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aws-lambda-api-tools",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"generate-oas": "./bin/generate-swagger.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublish-not": "npm run build && npm version patch -m 'Updated version to %s'",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"generate-swagger": "node -r ts-node/register bin/generate-swagger.js"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git@github.com:wesreid/pkg-core-app-sdk.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "",
|
|
22
|
+
"license": "UNLICENSED",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/atob": "^2.1.4",
|
|
25
|
+
"@types/aws-lambda": "^8.10.146",
|
|
26
|
+
"@types/formidable": "^1.2.8",
|
|
27
|
+
"@types/jest": "^26.0.24",
|
|
28
|
+
"@types/minimist": "^1.2.5",
|
|
29
|
+
"@types/node": "^15.14.9",
|
|
30
|
+
"@types/node-fetch": "^2.6.12",
|
|
31
|
+
"esbuild": "^0.12.29",
|
|
32
|
+
"jest": "^26.6.3",
|
|
33
|
+
"nodemon": "^2.0.22",
|
|
34
|
+
"prettier": "^2.8.8",
|
|
35
|
+
"ts-jest": "^26.5.6",
|
|
36
|
+
"ts-node": "^9.1.1",
|
|
37
|
+
"typescript": "^4.9.5"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"atob": "^2.1.2",
|
|
41
|
+
"joi": "^17.13.3",
|
|
42
|
+
"joi-to-swagger": "^5.2.0",
|
|
43
|
+
"minimist": "^1.2.8"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"bin",
|
|
47
|
+
"dist"
|
|
48
|
+
]
|
|
49
|
+
}
|