@spytecgps/lambda-utils 2.2.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/index.d.ts +13 -0
- package/dist/errors/BadRequestError.d.ts +6 -6
- package/dist/errors/BaseError.d.ts +4 -4
- package/dist/errors/ConflictError.d.ts +6 -6
- package/dist/errors/ForbiddenError.d.ts +6 -6
- package/dist/errors/HttpError.d.ts +8 -8
- package/dist/errors/NotFoundError.d.ts +6 -6
- package/dist/errors/UnauthorizedError.d.ts +6 -6
- package/dist/errors/index.d.ts +8 -8
- package/dist/index.d.ts +8 -7
- package/dist/index.js +1 -1
- package/dist/logger/index.d.ts +2 -2
- package/dist/middleware/contextualLogger.d.ts +12 -12
- package/dist/middleware/index.d.ts +23 -21
- package/dist/middleware/ioLogger.d.ts +1 -1
- package/dist/middleware/middleware.test.d.ts +1 -1
- package/dist/middleware/responseWrapper.d.ts +4 -4
- package/dist/middleware/types.d.ts +7 -7
- package/dist/middleware/validation.d.ts +9 -9
- package/dist/middleware/warmup.d.ts +3 -3
- package/dist/types.d.ts +73 -73
- package/dist/utils/cache.d.ts +23 -23
- package/dist/utils/cacheWrapper.d.ts +2 -2
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/timeOut.d.ts +1 -1
- package/dist/validation/custom.d.ts +18 -18
- package/dist/validation/index.d.ts +6 -6
- package/dist/validation/requestContext.d.ts +14 -14
- package/dist/validation/validateEvent.d.ts +3 -3
- package/dist/wrappers/apiGatewayEventWrapper.d.ts +4 -4
- package/dist/wrappers/index.d.ts +5 -5
- package/dist/wrappers/response.d.ts +8 -8
- package/dist/wrappers/sqsEventWrapper.d.ts +3 -3
- package/dist/wrappers/sqsEventWrapperWithReturn.d.ts +3 -3
- package/package.json +2 -2
- package/dist/errors/BadRequestError.js +0 -28
- package/dist/errors/BaseError.js +0 -24
- package/dist/errors/HttpError.js +0 -32
- package/dist/errors/NotFoundError.js +0 -28
- package/dist/errors/UnauthorizedError.js +0 -28
- package/dist/errors/index.js +0 -12
- package/dist/logger/logger.d.ts +0 -3
- package/dist/logger/logger.js +0 -57
- package/dist/middleware/contextualLogger.js +0 -87
- package/dist/middleware/index.js +0 -62
- package/dist/middleware/ioLogger.js +0 -14
- package/dist/middleware/middleware.test.js +0 -167
- package/dist/middleware/responseWrapper.js +0 -12
- package/dist/middleware/types.js +0 -2
- package/dist/middleware/validation.js +0 -27
- package/dist/types.js +0 -2
- package/dist/validation/custom.js +0 -122
- package/dist/validation/index.js +0 -20
- package/dist/validation/requestContext.js +0 -54
- package/dist/validation/validateEvent.js +0 -25
- package/dist/wrappers/apiGatewayEventWrapper.js +0 -82
- package/dist/wrappers/index.js +0 -21
- package/dist/wrappers/response.js +0 -35
- package/dist/wrappers/sqsEventWrapper.js +0 -116
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
|
|
2
|
-
import * as Joi from 'joi';
|
|
3
|
-
import { AuthClass, SpytecAuthContext } from '../types';
|
|
4
|
-
interface GetAuthorizerValidatorParams {
|
|
5
|
-
scope?: string;
|
|
6
|
-
type?: AuthClass;
|
|
7
|
-
}
|
|
8
|
-
export declare const getAuthorizerValidator: ({ scope, type }?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<SpytecAuthContext>;
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated
|
|
11
|
-
*/
|
|
12
|
-
export declare const requestContextValidator: Joi.ObjectSchema<any>;
|
|
13
|
-
export declare const getRequestContextValidator: (params?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<APIGatewayEventRequestContextWithAuthorizer<SpytecAuthContext>>;
|
|
14
|
-
export {};
|
|
1
|
+
import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
|
|
2
|
+
import * as Joi from 'joi';
|
|
3
|
+
import { AuthClass, SpytecAuthContext } from '../types';
|
|
4
|
+
interface GetAuthorizerValidatorParams {
|
|
5
|
+
scope?: string;
|
|
6
|
+
type?: AuthClass;
|
|
7
|
+
}
|
|
8
|
+
export declare const getAuthorizerValidator: ({ scope, type }?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<SpytecAuthContext>;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
export declare const requestContextValidator: Joi.ObjectSchema<any>;
|
|
13
|
+
export declare const getRequestContextValidator: (params?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<APIGatewayEventRequestContextWithAuthorizer<SpytecAuthContext>>;
|
|
14
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ObjectSchema, ValidationOptions } from 'joi';
|
|
2
|
-
declare const validateEvent: <T>(event: any, schema?: ObjectSchema<T>, validateOptions?: ValidationOptions) => T;
|
|
3
|
-
export default validateEvent;
|
|
1
|
+
import { ObjectSchema, ValidationOptions } from 'joi';
|
|
2
|
+
declare const validateEvent: <T>(event: any, schema?: ObjectSchema<T>, validateOptions?: ValidationOptions) => T;
|
|
3
|
+
export default validateEvent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIGatewayProxyResult } from 'aws-lambda';
|
|
2
|
-
import { WrapperArgs } from '../types';
|
|
3
|
-
declare const apiGatewayEventWrapper: <E, R>({ event, context, schema, handler, }: WrapperArgs<E, R>) => Promise<APIGatewayProxyResult>;
|
|
4
|
-
export default apiGatewayEventWrapper;
|
|
1
|
+
import { APIGatewayProxyResult } from 'aws-lambda';
|
|
2
|
+
import { WrapperArgs } from '../types';
|
|
3
|
+
declare const apiGatewayEventWrapper: <E, R>({ event, context, schema, handler, }: WrapperArgs<E, R>) => Promise<APIGatewayProxyResult>;
|
|
4
|
+
export default apiGatewayEventWrapper;
|
package/dist/wrappers/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import apiGatewayEventWrapper from './apiGatewayEventWrapper';
|
|
2
|
-
import sqsEventWrapper from './sqsEventWrapper';
|
|
3
|
-
import sqsEventWrapperWithReturn from './sqsEventWrapperWithReturn';
|
|
4
|
-
export { apiGatewayEventWrapper, sqsEventWrapper, sqsEventWrapperWithReturn };
|
|
5
|
-
export * from './response';
|
|
1
|
+
import apiGatewayEventWrapper from './apiGatewayEventWrapper';
|
|
2
|
+
import sqsEventWrapper from './sqsEventWrapper';
|
|
3
|
+
import sqsEventWrapperWithReturn from './sqsEventWrapperWithReturn';
|
|
4
|
+
export { apiGatewayEventWrapper, sqsEventWrapper, sqsEventWrapperWithReturn };
|
|
5
|
+
export * from './response';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { APIGatewayProxyResult } from 'aws-lambda';
|
|
2
|
-
import { HandlerResponse } from '../types';
|
|
3
|
-
export declare const buildResponseBody: <T>(statusCode: number, message: string, data?: T) => {
|
|
4
|
-
success: boolean;
|
|
5
|
-
message: string;
|
|
6
|
-
result: T;
|
|
7
|
-
};
|
|
8
|
-
export declare const buildProxyResult: <R>({ statusCode, message, data, headers, rawResult, stringifyBody, }: HandlerResponse<R>) => APIGatewayProxyResult;
|
|
1
|
+
import { APIGatewayProxyResult } from 'aws-lambda';
|
|
2
|
+
import { HandlerResponse } from '../types';
|
|
3
|
+
export declare const buildResponseBody: <T>(statusCode: number, message: string, data?: T) => {
|
|
4
|
+
success: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
result: T;
|
|
7
|
+
};
|
|
8
|
+
export declare const buildProxyResult: <R>({ statusCode, message, data, headers, rawResult, stringifyBody, }: HandlerResponse<R>) => APIGatewayProxyResult;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BaseRecord, SQSWrapperArgs } from '../types';
|
|
2
|
-
declare const sqsEventWrapper: <RecordType extends BaseRecord>({ event, context, schema, handler, singleHandler, mode, }: SQSWrapperArgs<RecordType>) => Promise<void>;
|
|
3
|
-
export default sqsEventWrapper;
|
|
1
|
+
import { BaseRecord, SQSWrapperArgs } from '../types';
|
|
2
|
+
declare const sqsEventWrapper: <RecordType extends BaseRecord>({ event, context, schema, handler, singleHandler, mode, }: SQSWrapperArgs<RecordType>) => Promise<void>;
|
|
3
|
+
export default sqsEventWrapper;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BaseRecord, SQSWrapperArgsWithReturn } from '../types';
|
|
2
|
-
declare const sqsEventWrapper: <RecordType extends BaseRecord, T>({ event, context, schema, handler, singleHandler, mode, }: SQSWrapperArgsWithReturn<RecordType, T>) => Promise<T | T[]>;
|
|
3
|
-
export default sqsEventWrapper;
|
|
1
|
+
import { BaseRecord, SQSWrapperArgsWithReturn } from '../types';
|
|
2
|
+
declare const sqsEventWrapper: <RecordType extends BaseRecord, T>({ event, context, schema, handler, singleHandler, mode, }: SQSWrapperArgsWithReturn<RecordType, T>) => Promise<T | T[]>;
|
|
3
|
+
export default sqsEventWrapper;
|
package/package.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
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;
|
package/dist/errors/BaseError.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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;
|
package/dist/errors/HttpError.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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,28 +0,0 @@
|
|
|
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,28 +0,0 @@
|
|
|
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;
|
package/dist/errors/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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/logger/logger.d.ts
DELETED
package/dist/logger/logger.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logger = exports.isTest = exports.isLocal = void 0;
|
|
4
|
-
var winston_1 = require("winston");
|
|
5
|
-
var winston_console_format_1 = require("winston-console-format");
|
|
6
|
-
var combine = winston_1.format.combine, errors = winston_1.format.errors, json = winston_1.format.json, timestamp = winston_1.format.timestamp, colorize = winston_1.format.colorize, padLevels = winston_1.format.padLevels;
|
|
7
|
-
exports.isLocal = function () { return !!process.env.IS_OFFLINE; };
|
|
8
|
-
exports.isTest = function () { return process.env.NODE_ENV == 'test'; };
|
|
9
|
-
var replaceError = function (_a) {
|
|
10
|
-
var label = _a.label, level = _a.level, message = _a.message, stack = _a.stack;
|
|
11
|
-
return ({
|
|
12
|
-
label: label,
|
|
13
|
-
level: level,
|
|
14
|
-
message: message,
|
|
15
|
-
stack: stack,
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
var replacer = function (_key, value) {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
return value instanceof Error ? replaceError(value) : value;
|
|
21
|
-
};
|
|
22
|
-
function getDevFormat() {
|
|
23
|
-
return combine(timestamp(), colorize({ all: true }), padLevels(), winston_console_format_1.consoleFormat({
|
|
24
|
-
showMeta: true,
|
|
25
|
-
metaStrip: [
|
|
26
|
-
'timestamp',
|
|
27
|
-
'service',
|
|
28
|
-
'requestId',
|
|
29
|
-
'x-correlation-id',
|
|
30
|
-
'function',
|
|
31
|
-
'contextUserId',
|
|
32
|
-
'contextUserEmail',
|
|
33
|
-
],
|
|
34
|
-
inspectOptions: {
|
|
35
|
-
depth: Infinity,
|
|
36
|
-
colors: true,
|
|
37
|
-
maxArrayLength: Infinity,
|
|
38
|
-
breakLength: 120,
|
|
39
|
-
compact: Infinity,
|
|
40
|
-
},
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
function getProductionFormat() {
|
|
44
|
-
return combine(errors({ stack: true }), timestamp(), json({ replacer: replacer }));
|
|
45
|
-
}
|
|
46
|
-
function getFormat() {
|
|
47
|
-
if (exports.isTest() || exports.isLocal()) {
|
|
48
|
-
return getDevFormat();
|
|
49
|
-
}
|
|
50
|
-
return getProductionFormat();
|
|
51
|
-
}
|
|
52
|
-
exports.logger = winston_1.createLogger({
|
|
53
|
-
level: exports.isTest() || exports.isLocal() ? 'info' : 'verbose',
|
|
54
|
-
defaultMeta: {},
|
|
55
|
-
format: getFormat(),
|
|
56
|
-
transports: [new winston_1.transports.Console()],
|
|
57
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
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 logger_1 = require("../logger/logger");
|
|
41
|
-
var AMAZON_TRACE_ID = '_X_AMZN_TRACE_ID';
|
|
42
|
-
var CORRELATION_HEADER = 'x-correlation-';
|
|
43
|
-
var CORRELATION_ID = CORRELATION_HEADER + "id";
|
|
44
|
-
var CORRELATION_TRACE_ID = CORRELATION_HEADER + "trace-id";
|
|
45
|
-
/**
|
|
46
|
-
* Adapted from https://github.com/FormidableLabs/pino-lambda/blob/master/src/request.ts
|
|
47
|
-
*/
|
|
48
|
-
exports.contextualLogger = function () {
|
|
49
|
-
var ctx = logger_1.logger.defaultMeta;
|
|
50
|
-
var before = function (_a) {
|
|
51
|
-
var event = _a.event, context = _a.context;
|
|
52
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
-
var apiEvent_1;
|
|
54
|
-
var _b, _c, _d, _e, _f, _g, _h;
|
|
55
|
-
return __generator(this, function (_j) {
|
|
56
|
-
if (context) {
|
|
57
|
-
ctx.requestId = context === null || context === void 0 ? void 0 : context.awsRequestId;
|
|
58
|
-
ctx.function = context.functionName;
|
|
59
|
-
}
|
|
60
|
-
if (!ctx.requestId) {
|
|
61
|
-
ctx.requestId = (_b = event === null || event === void 0 ? void 0 : event.requestContext) === null || _b === void 0 ? void 0 : _b.requestId;
|
|
62
|
-
}
|
|
63
|
-
if (Object(event).hasOwnProperty('headers')) {
|
|
64
|
-
apiEvent_1 = event;
|
|
65
|
-
Object.keys(apiEvent_1).forEach(function (header) {
|
|
66
|
-
if (header.toLowerCase().startsWith(CORRELATION_HEADER)) {
|
|
67
|
-
ctx[header] = apiEvent_1[header];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (process.env[AMAZON_TRACE_ID]) {
|
|
72
|
-
ctx[CORRELATION_TRACE_ID] = process.env[AMAZON_TRACE_ID];
|
|
73
|
-
}
|
|
74
|
-
if (!ctx[CORRELATION_ID]) {
|
|
75
|
-
ctx[CORRELATION_ID] = context === null || context === void 0 ? void 0 : context.awsRequestId;
|
|
76
|
-
}
|
|
77
|
-
ctx.contextUserId = (_e = (_d = (_c = event === null || event === void 0 ? void 0 : event.requestContext) === null || _c === void 0 ? void 0 : _c.authorizer) === null || _d === void 0 ? void 0 : _d.claims) === null || _e === void 0 ? void 0 : _e.userId;
|
|
78
|
-
ctx.contextUserEmail = (_h = (_g = (_f = event === null || event === void 0 ? void 0 : event.requestContext) === null || _f === void 0 ? void 0 : _f.authorizer) === null || _g === void 0 ? void 0 : _g.claims) === null || _h === void 0 ? void 0 : _h.email;
|
|
79
|
-
return [2 /*return*/];
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
return {
|
|
84
|
-
before: before,
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
exports.contextualLoggerMiddleware = exports.contextualLogger();
|
package/dist/middleware/index.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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 responseWrapper_1 = require("./responseWrapper");
|
|
24
|
-
var logger_1 = require("../logger/logger");
|
|
25
|
-
var baseMiddlewares = [contextualLogger_1.contextualLoggerMiddleware, ioLogger_1.ioLoggerMiddleware];
|
|
26
|
-
var apiGatewayMiddlewares = [
|
|
27
|
-
http_response_serializer_1.default({
|
|
28
|
-
serializers: [
|
|
29
|
-
{
|
|
30
|
-
regex: /^application\/xml$/,
|
|
31
|
-
serializer: function (_a) {
|
|
32
|
-
var body = _a.body;
|
|
33
|
-
return "<message>" + body + "</message>";
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
regex: /^application\/json$/,
|
|
38
|
-
serializer: function (_a) {
|
|
39
|
-
var body = _a.body;
|
|
40
|
-
return JSON.stringify(body);
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
regex: /^text\/plain$/,
|
|
45
|
-
serializer: function (_a) {
|
|
46
|
-
var body = _a.body;
|
|
47
|
-
return body;
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
default: 'application/json',
|
|
52
|
-
}),
|
|
53
|
-
http_error_handler_1.default({
|
|
54
|
-
logger: function (error) { return logger_1.logger.error(error); },
|
|
55
|
-
}),
|
|
56
|
-
responseWrapper_1.responseWrapperMiddleware(),
|
|
57
|
-
];
|
|
58
|
-
exports.apiGatewayMiddlewares = apiGatewayMiddlewares;
|
|
59
|
-
var middy = function (handler) { return core_1.default(handler).use(__spreadArrays(baseMiddlewares)); };
|
|
60
|
-
exports.middy = middy;
|
|
61
|
-
var apiGatewayMiddy = function (handler) { return core_1.default(handler).use(__spreadArrays(baseMiddlewares, apiGatewayMiddlewares)); };
|
|
62
|
-
exports.apiGatewayMiddy = apiGatewayMiddy;
|
|
@@ -1,14 +0,0 @@
|
|
|
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 logger_1 = require("../logger/logger");
|
|
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
|
-
logger_1.logger.info(message, req);
|
|
13
|
-
},
|
|
14
|
-
});
|