@spytecgps/lambda-utils 0.9.23 → 1.0.0-rc2

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.
Files changed (45) hide show
  1. package/dist/errors/BadRequestError.d.ts +6 -5
  2. package/dist/errors/BadRequestError.js +28 -27
  3. package/dist/errors/BaseError.d.ts +3 -3
  4. package/dist/errors/BaseError.js +24 -24
  5. package/dist/errors/HttpError.d.ts +8 -0
  6. package/dist/errors/HttpError.js +32 -0
  7. package/dist/errors/NotFoundError.d.ts +6 -5
  8. package/dist/errors/NotFoundError.js +28 -27
  9. package/dist/errors/UnauthorizedError.d.ts +6 -5
  10. package/dist/errors/UnauthorizedError.js +28 -27
  11. package/dist/errors/index.d.ts +4 -4
  12. package/dist/errors/index.js +12 -9
  13. package/dist/index.d.ts +4 -4
  14. package/dist/index.js +16 -16
  15. package/dist/middleware/contextualLogger.d.ts +12 -0
  16. package/dist/middleware/contextualLogger.js +55 -0
  17. package/dist/middleware/index.d.ts +10 -0
  18. package/dist/middleware/index.js +60 -0
  19. package/dist/middleware/ioLogger.d.ts +1 -0
  20. package/dist/middleware/ioLogger.js +14 -0
  21. package/dist/middleware/middleware.test.d.ts +1 -0
  22. package/dist/middleware/middleware.test.js +121 -0
  23. package/dist/middleware/types.d.ts +7 -0
  24. package/dist/middleware/types.js +2 -0
  25. package/dist/middleware/validation.d.ts +9 -0
  26. package/dist/middleware/validation.js +27 -0
  27. package/dist/types.d.ts +49 -59
  28. package/dist/types.js +2 -2
  29. package/dist/validation/custom.d.ts +16 -16
  30. package/dist/validation/custom.js +122 -103
  31. package/dist/validation/index.d.ts +4 -4
  32. package/dist/validation/index.js +20 -17
  33. package/dist/validation/requestContext.d.ts +14 -14
  34. package/dist/validation/requestContext.js +54 -35
  35. package/dist/validation/validateEvent.d.ts +3 -3
  36. package/dist/validation/validateEvent.js +25 -25
  37. package/dist/wrappers/apiGatewayEventWrapper.d.ts +4 -4
  38. package/dist/wrappers/apiGatewayEventWrapper.js +82 -120
  39. package/dist/wrappers/index.d.ts +4 -4
  40. package/dist/wrappers/index.js +21 -18
  41. package/dist/wrappers/response.d.ts +8 -8
  42. package/dist/wrappers/response.js +35 -35
  43. package/dist/wrappers/sqsEventWrapper.d.ts +3 -3
  44. package/dist/wrappers/sqsEventWrapper.js +116 -113
  45. package/package.json +6 -2
@@ -1,5 +1,6 @@
1
- import { BaseError } from './BaseError';
2
- export default class BadRequestError extends BaseError {
3
- code: number;
4
- name: string;
5
- }
1
+ import { HttpError } from './HttpError';
2
+ export default class BadRequestError extends HttpError {
3
+ code: number;
4
+ statusCode: number;
5
+ name: string;
6
+ }
@@ -1,27 +1,28 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseError_1 = require("./BaseError");
17
- var BadRequestError = /** @class */ (function (_super) {
18
- __extends(BadRequestError, _super);
19
- function BadRequestError() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.code = 400;
22
- _this.name = 'BadRequestError';
23
- return _this;
24
- }
25
- return BadRequestError;
26
- }(BaseError_1.BaseError));
27
- exports.default = BadRequestError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var HttpError_1 = require("./HttpError");
17
+ var BadRequestError = /** @class */ (function (_super) {
18
+ __extends(BadRequestError, _super);
19
+ function BadRequestError() {
20
+ var _this = _super !== null && _super.apply(this, arguments) || this;
21
+ _this.code = 400;
22
+ _this.statusCode = 400;
23
+ _this.name = 'BadRequestError';
24
+ return _this;
25
+ }
26
+ return BadRequestError;
27
+ }(HttpError_1.HttpError));
28
+ exports.default = BadRequestError;
@@ -1,3 +1,3 @@
1
- export declare abstract class BaseError extends Error {
2
- abstract code: number;
3
- }
1
+ export declare abstract class BaseError extends Error {
2
+ abstract code: number;
3
+ }
@@ -1,24 +1,24 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.BaseError = void 0;
17
- var BaseError = /** @class */ (function (_super) {
18
- __extends(BaseError, _super);
19
- function BaseError() {
20
- return _super !== null && _super.apply(this, arguments) || this;
21
- }
22
- return BaseError;
23
- }(Error));
24
- exports.BaseError = BaseError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.BaseError = void 0;
17
+ var BaseError = /** @class */ (function (_super) {
18
+ __extends(BaseError, _super);
19
+ function BaseError() {
20
+ return _super !== null && _super.apply(this, arguments) || this;
21
+ }
22
+ return BaseError;
23
+ }(Error));
24
+ exports.BaseError = BaseError;
@@ -0,0 +1,8 @@
1
+ export declare abstract class HttpError extends Error {
2
+ abstract code: number;
3
+ abstract statusCode: number;
4
+ }
5
+ export declare class BaseError extends Error {
6
+ code: 500;
7
+ statusCode: 500;
8
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.BaseError = exports.HttpError = void 0;
17
+ var HttpError = /** @class */ (function (_super) {
18
+ __extends(HttpError, _super);
19
+ function HttpError() {
20
+ return _super !== null && _super.apply(this, arguments) || this;
21
+ }
22
+ return HttpError;
23
+ }(Error));
24
+ exports.HttpError = HttpError;
25
+ var BaseError = /** @class */ (function (_super) {
26
+ __extends(BaseError, _super);
27
+ function BaseError() {
28
+ return _super !== null && _super.apply(this, arguments) || this;
29
+ }
30
+ return BaseError;
31
+ }(Error));
32
+ exports.BaseError = BaseError;
@@ -1,5 +1,6 @@
1
- import { BaseError } from './BaseError';
2
- export default class NotFoundError extends BaseError {
3
- code: number;
4
- name: string;
5
- }
1
+ import { HttpError } from './HttpError';
2
+ export default class NotFoundError extends HttpError {
3
+ code: number;
4
+ statusCode: number;
5
+ name: string;
6
+ }
@@ -1,27 +1,28 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseError_1 = require("./BaseError");
17
- var NotFoundError = /** @class */ (function (_super) {
18
- __extends(NotFoundError, _super);
19
- function NotFoundError() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.code = 404;
22
- _this.name = 'NotFoundError';
23
- return _this;
24
- }
25
- return NotFoundError;
26
- }(BaseError_1.BaseError));
27
- exports.default = NotFoundError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var HttpError_1 = require("./HttpError");
17
+ var NotFoundError = /** @class */ (function (_super) {
18
+ __extends(NotFoundError, _super);
19
+ function NotFoundError() {
20
+ var _this = _super !== null && _super.apply(this, arguments) || this;
21
+ _this.code = 404;
22
+ _this.statusCode = 404;
23
+ _this.name = 'NotFoundError';
24
+ return _this;
25
+ }
26
+ return NotFoundError;
27
+ }(HttpError_1.HttpError));
28
+ exports.default = NotFoundError;
@@ -1,5 +1,6 @@
1
- import { BaseError } from './BaseError';
2
- export default class UnauthorizedError extends BaseError {
3
- code: number;
4
- name: string;
5
- }
1
+ import { HttpError } from './HttpError';
2
+ export default class UnauthorizedError extends HttpError {
3
+ code: number;
4
+ statusCode: number;
5
+ name: string;
6
+ }
@@ -1,27 +1,28 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseError_1 = require("./BaseError");
17
- var UnauthorizedError = /** @class */ (function (_super) {
18
- __extends(UnauthorizedError, _super);
19
- function UnauthorizedError() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.code = 401;
22
- _this.name = 'UnauthorizedError';
23
- return _this;
24
- }
25
- return UnauthorizedError;
26
- }(BaseError_1.BaseError));
27
- exports.default = UnauthorizedError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var HttpError_1 = require("./HttpError");
17
+ var UnauthorizedError = /** @class */ (function (_super) {
18
+ __extends(UnauthorizedError, _super);
19
+ function UnauthorizedError() {
20
+ var _this = _super !== null && _super.apply(this, arguments) || this;
21
+ _this.code = 401;
22
+ _this.statusCode = 401;
23
+ _this.name = 'UnauthorizedError';
24
+ return _this;
25
+ }
26
+ return UnauthorizedError;
27
+ }(HttpError_1.HttpError));
28
+ exports.default = UnauthorizedError;
@@ -1,4 +1,4 @@
1
- import BadRequestError from './BadRequestError';
2
- import NotFoundError from './NotFoundError';
3
- import UnauthorizedError from './UnauthorizedError';
4
- export { BadRequestError, NotFoundError, UnauthorizedError };
1
+ import BadRequestError from './BadRequestError';
2
+ import NotFoundError from './NotFoundError';
3
+ import UnauthorizedError from './UnauthorizedError';
4
+ export { BadRequestError, NotFoundError, UnauthorizedError };
@@ -1,9 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnauthorizedError = exports.NotFoundError = exports.BadRequestError = void 0;
4
- var BadRequestError_1 = require("./BadRequestError");
5
- exports.BadRequestError = BadRequestError_1.default;
6
- var NotFoundError_1 = require("./NotFoundError");
7
- exports.NotFoundError = NotFoundError_1.default;
8
- var UnauthorizedError_1 = require("./UnauthorizedError");
9
- exports.UnauthorizedError = UnauthorizedError_1.default;
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.UnauthorizedError = exports.NotFoundError = exports.BadRequestError = void 0;
7
+ var BadRequestError_1 = __importDefault(require("./BadRequestError"));
8
+ exports.BadRequestError = BadRequestError_1.default;
9
+ var NotFoundError_1 = __importDefault(require("./NotFoundError"));
10
+ exports.NotFoundError = NotFoundError_1.default;
11
+ var UnauthorizedError_1 = __importDefault(require("./UnauthorizedError"));
12
+ exports.UnauthorizedError = UnauthorizedError_1.default;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './wrappers';
2
- export * from './errors';
3
- export * from './validation';
4
- export * from './types';
1
+ export * from './wrappers';
2
+ export * from './errors';
3
+ export * from './validation';
4
+ export * from './types';
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./wrappers"), exports);
14
- __exportStar(require("./errors"), exports);
15
- __exportStar(require("./validation"), exports);
16
- __exportStar(require("./types"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./wrappers"), exports);
14
+ __exportStar(require("./errors"), exports);
15
+ __exportStar(require("./validation"), exports);
16
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,12 @@
1
+ export declare const contextualLogger: () => {
2
+ before: ({ event, context }: {
3
+ event: any;
4
+ context: any;
5
+ }) => Promise<void>;
6
+ };
7
+ export declare const contextualLoggerMiddleware: {
8
+ before: ({ event, context }: {
9
+ event: any;
10
+ context: any;
11
+ }) => Promise<void>;
12
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.contextualLoggerMiddleware = exports.contextualLogger = void 0;
40
+ var sdk_1 = require("@spytecgps/sdk");
41
+ exports.contextualLogger = function () {
42
+ var before = function (_a) {
43
+ var event = _a.event, context = _a.context;
44
+ return __awaiter(void 0, void 0, void 0, function () {
45
+ return __generator(this, function (_b) {
46
+ sdk_1.logger.withRequest(event, context);
47
+ return [2 /*return*/];
48
+ });
49
+ });
50
+ };
51
+ return {
52
+ before: before,
53
+ };
54
+ };
55
+ exports.contextualLoggerMiddleware = exports.contextualLogger();
@@ -0,0 +1,10 @@
1
+ import rawMiddy from '@middy/core';
2
+ import httpErrorHandler from '@middy/http-error-handler';
3
+ import httpResponseSerializer from '@middy/http-response-serializer';
4
+ import { validatorMiddleware } from './validation';
5
+ import { Context as LambdaContext } from 'aws-lambda/handler';
6
+ import { MiddyInputHandler } from './types';
7
+ declare const apiGatewayMiddlewares: rawMiddy.MiddlewareObj<any, any, Error, LambdaContext>[];
8
+ declare const middy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
9
+ declare const apiGatewayMiddy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
10
+ export { middy, apiGatewayMiddy, httpErrorHandler, httpResponseSerializer, validatorMiddleware, apiGatewayMiddlewares };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
8
+ };
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.apiGatewayMiddlewares = exports.validatorMiddleware = exports.httpResponseSerializer = exports.httpErrorHandler = exports.apiGatewayMiddy = exports.middy = void 0;
14
+ var core_1 = __importDefault(require("@middy/core"));
15
+ var http_error_handler_1 = __importDefault(require("@middy/http-error-handler"));
16
+ exports.httpErrorHandler = http_error_handler_1.default;
17
+ var http_response_serializer_1 = __importDefault(require("@middy/http-response-serializer"));
18
+ exports.httpResponseSerializer = http_response_serializer_1.default;
19
+ var contextualLogger_1 = require("./contextualLogger");
20
+ var ioLogger_1 = require("./ioLogger");
21
+ var validation_1 = require("./validation");
22
+ Object.defineProperty(exports, "validatorMiddleware", { enumerable: true, get: function () { return validation_1.validatorMiddleware; } });
23
+ var sdk_1 = require("@spytecgps/sdk");
24
+ var baseMiddlewares = [contextualLogger_1.contextualLoggerMiddleware, ioLogger_1.ioLoggerMiddleware];
25
+ var apiGatewayMiddlewares = [
26
+ http_response_serializer_1.default({
27
+ serializers: [
28
+ {
29
+ regex: /^application\/xml$/,
30
+ serializer: function (_a) {
31
+ var body = _a.body;
32
+ return "<message>" + body + "</message>";
33
+ },
34
+ },
35
+ {
36
+ regex: /^application\/json$/,
37
+ serializer: function (_a) {
38
+ var body = _a.body;
39
+ return JSON.stringify(body);
40
+ },
41
+ },
42
+ {
43
+ regex: /^text\/plain$/,
44
+ serializer: function (_a) {
45
+ var body = _a.body;
46
+ return body;
47
+ },
48
+ },
49
+ ],
50
+ default: 'application/json',
51
+ }),
52
+ http_error_handler_1.default({
53
+ logger: function (error) { return sdk_1.logger.error(error); },
54
+ }),
55
+ ];
56
+ exports.apiGatewayMiddlewares = apiGatewayMiddlewares;
57
+ var middy = function (handler) { return core_1.default(handler).use(__spreadArrays(baseMiddlewares)); };
58
+ exports.middy = middy;
59
+ var apiGatewayMiddy = function (handler) { return core_1.default(handler).use(__spreadArrays(baseMiddlewares)); };
60
+ exports.apiGatewayMiddy = apiGatewayMiddy;
@@ -0,0 +1 @@
1
+ export declare const ioLoggerMiddleware: import("@middy/core").MiddlewareObj<any, any, Error, import("aws-lambda").Context>;
@@ -0,0 +1,14 @@
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.ioLoggerMiddleware = void 0;
7
+ var input_output_logger_1 = __importDefault(require("@middy/input-output-logger"));
8
+ var sdk_1 = require("@spytecgps/sdk");
9
+ exports.ioLoggerMiddleware = input_output_logger_1.default({
10
+ logger: function (req) {
11
+ var message = (req === null || req === void 0 ? void 0 : req.event) ? 'event' : 'response';
12
+ sdk_1.logger.info(req, message);
13
+ },
14
+ });
@@ -0,0 +1 @@
1
+ export {};