@spytecgps/lambda-utils 1.0.19 → 2.0.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/README.md +6 -1
- package/dist/errors/index.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -19
- package/dist/logger/index.d.ts +4 -0
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/types.d.ts +2 -2
- package/dist/types.d.ts +12 -12
- package/dist/validation/custom.d.ts +1 -0
- package/dist/validation/index.d.ts +2 -1
- package/dist/validation/requestContext.d.ts +1 -1
- package/dist/wrappers/sqsEventWrapper.d.ts +2 -2
- package/package.json +33 -33
- package/dist/errors/BadRequestError.js +0 -28
- package/dist/errors/ConflictError.js +0 -28
- package/dist/errors/ForbiddenError.js +0 -28
- 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 -16
- package/dist/logger/logger.d.ts +0 -3
- package/dist/logger/logger.js +0 -51
- 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/utils/cache.js +0 -58
- package/dist/utils/cacheWrapper.js +0 -55
- package/dist/utils/index.js +0 -17
- package/dist/utils/timeOut.js +0 -15
- package/dist/validation/custom.js +0 -143
- package/dist/validation/index.js +0 -25
- package/dist/validation/requestContext.js +0 -54
- package/dist/validation/validateEvent.js +0 -25
- package/dist/wrappers/apiGatewayEventWrapper.js +0 -79
- package/dist/wrappers/index.js +0 -21
- package/dist/wrappers/response.js +0 -36
- package/dist/wrappers/sqsEventWrapper.js +0 -120
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Utility functions for serverless packages
|
|
4
4
|
|
|
5
|
+
# Lambda Utils breaking changes
|
|
6
|
+
|
|
7
|
+
If you need to use this package on Node 14 last available version is 1.0.20
|
|
8
|
+
|
|
9
|
+
If you need to use this package on Node 16 first available version is 2.0.0
|
|
10
|
+
|
|
5
11
|
### Copy Distribution folder to local project ((local testing))
|
|
6
12
|
|
|
7
13
|
when making changes and would like to avoid commiting and publishing changes.
|
|
@@ -10,4 +16,3 @@ when making changes and would like to avoid commiting and publishing changes.
|
|
|
10
16
|
2. Run `npm run copydistfolder -- {destPath}` to copy distribution folder to local project
|
|
11
17
|
ex: `npm run copydistfolder -- ../api-reports` copies dist folder to folder -> `api-reports/node_modules/@spytecgps/lambda-utils/dist`
|
|
12
18
|
3. In order for VSCode to reload and get udpated api-core copied to node_modules dist folder -> On PC you can do Ctrl + Shift + P (mac: Cmd + Shift + P) then type "Reload Window"git
|
|
13
|
-
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BadRequestError from './BadRequestError';
|
|
2
|
+
import ConflictError from './ConflictError';
|
|
3
|
+
import ForbiddenError from './ForbiddenError';
|
|
2
4
|
import NotFoundError from './NotFoundError';
|
|
3
5
|
import UnauthorizedError from './UnauthorizedError';
|
|
4
|
-
import ForbiddenError from './ForbiddenError';
|
|
5
|
-
import ConflictError from './ConflictError';
|
|
6
6
|
export { BadRequestError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,19 +1 @@
|
|
|
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);
|
|
17
|
-
__exportStar(require("./middleware"), exports);
|
|
18
|
-
__exportStar(require("./logger/logger"), exports);
|
|
19
|
-
__exportStar(require("./utils"), exports);
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["lambda-utils"]=r():e["lambda-utils"]=r()}(global,(()=>(()=>{"use strict";var e={n:r=>{var t=r&&r.__esModule?()=>r.default:()=>r;return e.d(t,{a:t}),t},d:(r,t)=>{for(var a in t)e.o(t,a)&&!e.o(r,a)&&Object.defineProperty(r,a,{enumerable:!0,get:t[a]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{BadRequestError:()=>x,ConflictError:()=>N,ForbiddenError:()=>_,LambdaCache:()=>Q,NotFoundError:()=>T,SpytecJoi:()=>v,UnauthorizedError:()=>w,apiGatewayEventWrapper:()=>I,apiGatewayMiddlewares:()=>Z,apiGatewayMiddy:()=>K,buildProxyResult:()=>O,buildResponseBody:()=>S,defaultApiSchema:()=>A,getAuthorizerValidator:()=>f,getRequestContextValidator:()=>E,httpErrorHandler:()=>$(),httpResponseSerializer:()=>G(),iccidSchema:()=>b,imeiSchema:()=>g,json:()=>m,logger:()=>a,middy:()=>X,promiseWithCache:()=>Y,promiseWithTimeout:()=>ee,requestContextValidator:()=>C,resetLogger:()=>o,sqsEventWrapper:()=>R,urlEncoded:()=>y,validateEvent:()=>j,validatorMiddleware:()=>V,withRequest:()=>t.withRequest});const t=require("@spytecgps/sdk-logger");let a=(0,t.createLogger)();const o=e=>(a=(0,t.createLogger)({base:e}),a),s=require("dayjs");var n=e.n(s);const i=require("dayjs/plugin/timezone");var l=e.n(i);const c=require("dayjs/plugin/utc");var d=e.n(c);const u=require("joi"),p=require("qs");n().extend(d()),n().extend(l());const m=u.extend((e=>({type:"object",base:e.object(),messages:{"json.valid":"must be valid JSON"},coerce(e){try{return{value:JSON.parse(e)}}catch(e){return null}},validate:(e,r)=>e?{value:e}:{value:e,errors:r.error("json.valid")}}))),y=u.extend((e=>({type:"object",base:e.object(),coerce:e=>({value:p.parse(e)})}))),g=u.string().regex(/^\d{15,16}$/).message("Invalid IMEI"),b=u.string().regex(/^[0-9A-Za-z]{18,22}$/).message("Invalid ICCID"),v=u.extend((e=>({type:"imei",messages:"Invalid IMEI",base:e.string().regex(/^\d{15,16}$/)})),(e=>({type:"iccid",messages:"Invalid ICCID",base:e.string().regex(/^[0-9A-Za-z]{18,22}$/)})),(e=>({type:"urlEncodedObject",base:e.object(),coerce:e=>({value:p.parse(e)})})),(e=>({type:"jsonObject",base:e.object(),coerce(e){try{return{value:JSON.parse(e)}}catch(e){return null}},validate:(e,r)=>e?{value:e}:{value:e,errors:r.error("json.valid")}})),(e=>({type:"delimitedArray",base:e.array().default([]),coerce:e=>({value:e.split?e.split(","):e})})),(e=>({type:"queryStringParameters",messages:"Missing query parameters",base:e.object().required()})),(e=>({type:"date",base:e.date(),prepare(e,r){try{const r=n().tz(e,"UTC");if(r.isValid())return{value:r.toDate()}}catch(e){return r.error("any.invalid")}}})),(e=>({type:"jsonArray",base:e.array(),coerce(e){try{return{value:JSON.parse(e)}}catch(e){return{value:null}}},validate:(e,r)=>Array.isArray(e)?{value:e}:{value:e,errors:r.error("jsonArray.schema")}})),(e=>({type:"base64ThenUriEncodedObject",base:e.object(),coerce(e){try{const r=decodeURIComponent(Buffer.from(e,"base64").toString());return{value:JSON.parse(r)}}catch(e){return null}},validate:(e,r)=>e?{value:e}:{value:e,errors:r.error("json.valid")}})));class h extends Error{}class w extends h{code=401;statusCode=401;name="UnauthorizedError"}const f=({scope:e,type:r}={})=>u.object({clientId:u.number(),resources:m.object({}),scope:e?u.string().pattern(new RegExp(`${e}`)).error((()=>new w(`missing scope ${e}`))):u.optional(),type:r?u.any().valid(r).error((()=>new w(`missing user type ${r}`))):u.optional(),enterprise:u.boolean().default(!1),maintenanceModule:u.boolean().default(!1)}),C=u.object({authorizer:f()}),E=(e={})=>u.object({authorizer:f(e)});class x extends h{code=400;statusCode=400;name="BadRequestError"}const j=(e,r,t)=>{if(!r)return a.warn("skipping validation"),e;const{error:o,value:s}=r.validate(e,{allowUnknown:t?.allowUnknown||!0,errors:{label:"key",wrap:{label:!1}}});if(o)throw a.error({error:o},"Validation error"),o.isJoi?new x(o.message):o;return s},A=v.object({requestContext:E()}),q={"Content-Type":"application/json","Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":!0},S=(e,r,t)=>({success:e<400,message:r,result:t||void 0}),O=({statusCode:e=200,message:r="ok",data:t,headers:a={},rawResult:o=!1,stringifyBody:s=!0})=>{const n=o?t:S(e,r,t),i=s?n&&JSON.stringify(n):t;return{headers:{...q,...a},statusCode:e,body:i}},I=async({event:e,context:r,schema:o,handler:s})=>{e&&r&&(0,t.withRequest)(e,r);try{const r=j(e,o),t=await s(r);return O(t)}catch(r){return a.error({err:r,event:(n=e,{resource:n.resource,httpMethod:n.httpMethod,queryStringParameters:n.queryStringParameters,pathParameters:n.pathParameters,body:n.body})},"apiGatewayWrapper - caught error"),O({statusCode:r.code||500,message:r.message||"Error"})}var n},R=async({event:e,context:r,schema:o,handler:s,singleHandler:n,mode:i="serial"})=>{e&&r&&(0,t.withRequest)(e,r);try{const r=j(e,o);await async function(e,r,t,a){if(!r&&!t)throw new Error("handler or singleHandler not defined");if(r)await r(e);else if(t){const r=e.Records;if("serial"===a)for(const e of r)await t(e);else"parallel"===a&&await Promise.all(r.map((e=>t(e))))}}(r,s,n,i)}catch(r){throw a.error({err:r,event:(l=e,(l.Records||[]).map((e=>({messageId:e.messageId,body:e.body,messageAttributes:e.messageAttributes}))))},"sqsEventWrapper - caught error"),r}var l};class N extends h{code=409;statusCode=409;name="ConflictError"}class _ extends h{code=403;statusCode=403;name="ForbiddenError"}class T extends h{code=404;statusCode=404;name="NotFoundError"}const z=require("@middy/core");var M=e.n(z);const P=require("@middy/http-error-handler");var $=e.n(P);const U=require("@middy/http-response-serializer");var G=e.n(U);const k="_X_AMZN_TRACE_ID",H="x-correlation-",J=`${H}id`,W=`${H}trace-id`,D=(()=>{const e={};return{before:async({event:r,context:t})=>{if(t&&(e.requestId=t?.awsRequestId,e.function=t.functionName),e.requestId||(e.requestId=r?.requestContext?.requestId),Object.prototype.hasOwnProperty.call(r,"headers")){const t=r;Object.keys(t).forEach((r=>{r.toLowerCase().startsWith(H)&&(e[r]=t[r])}))}process.env[k]&&(e[W]=process.env[k]),e[J]||(e[J]=t?.awsRequestId),e.contextUserId=r?.requestContext?.authorizer?.claims?.userId,e.contextUserEmail=r?.requestContext?.authorizer?.claims?.email,o(e)}}})(),B=require("@middy/input-output-logger"),L=e.n(B)()({logger:e=>{const r=e?.event?"event":"response";a.info(r,e)}}),V=({schema:e,allowUnknown:r=!0})=>({before:t=>{const{error:o,value:s}=e.validate(t.event,{allowUnknown:r,errors:{label:"key",wrap:{label:!1}}});if(o)throw a.error("Validation error",{error:o}),o.isJoi?new x(o.message):o;t.event=s}}),F=[D,L],Z=[G()({serializers:[{regex:/^application\/xml$/,serializer:({body:e})=>`<message>${e}</message>`},{regex:/^application\/json$/,serializer:({body:e})=>JSON.stringify(e)},{regex:/^text\/plain$/,serializer:({body:e})=>e}],default:"application/json"}),$()({logger:e=>a.error(e)}),{after:e=>{e.response=O(e.response)}}],X=e=>M()(e).use([...F]),K=e=>M()(e).use([...F,...Z]);class Q{collectionName;constructor(e){this.collectionName=e??`${process.env.AWS_LAMBDA_FUNCTION_NAME}-${process.env.AWS_LAMBDA_FUNCTION_VERSION}`,global.CACHE_STORAGE||(global.CACHE_STORAGE={}),global.CACHE_STORAGE[this.collectionName]||(global.CACHE_STORAGE[this.collectionName]=new Map)}set(e,r,t){const a=1e3*t+Date.now();global.CACHE_STORAGE[this.collectionName].set(e,{value:r,expire:a})}get(e){if(!e)throw new Error("key is required!");const r=global.CACHE_STORAGE[this.collectionName].get(e);return r?!r.expire||r.expire>Date.now()?r.value:this.remove(e):null}remove(e){global.CACHE_STORAGE[this.collectionName].get(e)&&global.CACHE_STORAGE[this.collectionName].delete(e)}}const Y=async(e,r,t,a)=>{let o=r.get(t);return o||(o=await e(),r.set(t,o,a)),o},ee=(e,r,t=new Error("Promise timed out"))=>{const a=new Promise(((e,a)=>{setTimeout((()=>{a(t)}),r)}));return Promise.race([e,a])};return r})()));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import rawMiddy from '@middy/core';
|
|
2
2
|
import httpErrorHandler from '@middy/http-error-handler';
|
|
3
3
|
import httpResponseSerializer from '@middy/http-response-serializer';
|
|
4
|
-
import { validatorMiddleware } from './validation';
|
|
5
4
|
import { Context as LambdaContext } from 'aws-lambda/handler';
|
|
6
5
|
import { MiddyInputHandler } from './types';
|
|
6
|
+
import { validatorMiddleware } from './validation';
|
|
7
7
|
declare const apiGatewayMiddlewares: (rawMiddy.MiddlewareObj<any, any, Error, LambdaContext> | {
|
|
8
8
|
after: (req: any) => void;
|
|
9
9
|
})[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { APIGatewayProxyResult, Context as LambdaContext } from 'aws-lambda';
|
|
2
2
|
import { Callback as LambdaCallback } from 'aws-lambda/handler';
|
|
3
|
-
export
|
|
3
|
+
export type MiddyInputPromiseHandler<TEvent, TResult, TContext extends LambdaContext = LambdaContext> = (event: TEvent, context: TContext) => Promise<TResult>;
|
|
4
4
|
export interface APIResult<T = any> extends Omit<APIGatewayProxyResult, 'body'> {
|
|
5
5
|
body: T;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type MiddyInputHandler<TEvent, TResult, TContext extends LambdaContext = LambdaContext> = (event: TEvent, context: TContext, callback: LambdaCallback<TResult>) => Promise<TResult>;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { APIGatewayEventRequestContext, APIGatewayProxyEvent,
|
|
2
|
-
import {
|
|
1
|
+
import { APIGatewayEventRequestContext, APIGatewayProxyEvent, APIGatewayProxyWithCognitoAuthorizerEvent, APIGatewayProxyWithLambdaAuthorizerEvent, Context, SQSEvent, SQSRecord } from 'aws-lambda';
|
|
2
|
+
import { Callback } from 'aws-lambda/handler';
|
|
3
3
|
import { APIGatewayProxyEventBase } from 'aws-lambda/trigger/api-gateway-proxy';
|
|
4
|
+
import { ObjectSchema } from 'joi';
|
|
4
5
|
import * as Joi from 'joi';
|
|
5
|
-
import { Callback } from 'aws-lambda/handler';
|
|
6
6
|
export interface SpytecAuthorizedResources {
|
|
7
7
|
devices: string[];
|
|
8
8
|
boundaries: number[];
|
|
9
9
|
}
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
10
|
+
export type AuthClass = 'user' | 'client' | 'system';
|
|
11
|
+
export type DevicesAccess = 'full' | 'limited';
|
|
12
|
+
export type BoundariesAccess = 'full' | 'limited';
|
|
13
13
|
export interface SpytecAuthContext {
|
|
14
14
|
type: AuthClass;
|
|
15
15
|
userId?: string;
|
|
@@ -23,16 +23,16 @@ export interface SpytecAuthContext {
|
|
|
23
23
|
enterprise?: boolean;
|
|
24
24
|
maintenanceModule?: boolean;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type BaseAPIGatewayEvent = Omit<APIGatewayProxyEventBase<SpytecAuthContext>, 'pathParameters' | 'queryStringParameters' | 'body'>;
|
|
27
27
|
export interface WrapperArgs<E, R> {
|
|
28
28
|
event: APIGatewayProxyEvent;
|
|
29
29
|
context?: APIGatewayEventRequestContext;
|
|
30
30
|
schema?: ObjectSchema<E>;
|
|
31
31
|
handler: Handler<E, R>;
|
|
32
32
|
}
|
|
33
|
-
export
|
|
34
|
-
export
|
|
35
|
-
export
|
|
33
|
+
export type UserAPIHandler<TEvent = APIGatewayProxyWithLambdaAuthorizerEvent<SpytecAuthContext>, TResult = any> = (event: TEvent, context: APIGatewayEventRequestContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
34
|
+
export type ServerAPIHandler<TResult = any> = (event: APIGatewayProxyWithCognitoAuthorizerEvent, context: APIGatewayEventRequestContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
35
|
+
export type Handler<E, R> = (event: E) => Promise<HandlerResponse<R>>;
|
|
36
36
|
export interface HandlerResponse<R> {
|
|
37
37
|
statusCode?: number;
|
|
38
38
|
headers?: {
|
|
@@ -44,11 +44,11 @@ export interface HandlerResponse<R> {
|
|
|
44
44
|
rawResult?: boolean;
|
|
45
45
|
stringifyBody?: boolean;
|
|
46
46
|
}
|
|
47
|
-
export
|
|
47
|
+
export type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
|
|
48
48
|
export interface MessageEvent<RecordType extends BaseRecord> {
|
|
49
49
|
Records: RecordType[];
|
|
50
50
|
}
|
|
51
|
-
export
|
|
51
|
+
export type SQSWrapperArgs<RecordType extends BaseRecord> = {
|
|
52
52
|
event: SQSEvent;
|
|
53
53
|
context?: Context;
|
|
54
54
|
schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
|
|
@@ -12,6 +12,7 @@ interface SpytecJoi extends Joi.Root {
|
|
|
12
12
|
delimitedArray(): ArraySchema;
|
|
13
13
|
dateString(): StringSchema;
|
|
14
14
|
jsonArray<TSchema = any, T = TSchema>(schema?: Joi.SchemaMap<T>): ArraySchema<TSchema>;
|
|
15
|
+
base64ThenUriEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
|
|
15
16
|
}
|
|
16
17
|
export declare const SpytecJoi: SpytecJoi;
|
|
17
18
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { BaseAPIGatewayEvent } from '../types';
|
|
1
2
|
import validateEvent from './validateEvent';
|
|
2
3
|
export { validateEvent };
|
|
3
4
|
export * from './custom';
|
|
4
5
|
export * from './requestContext';
|
|
5
|
-
export declare const defaultApiSchema: import("joi").ObjectSchema<
|
|
6
|
+
export declare const defaultApiSchema: import("joi").ObjectSchema<BaseAPIGatewayEvent>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
|
|
1
2
|
import * as Joi from 'joi';
|
|
2
3
|
import { AuthClass, SpytecAuthContext } from '../types';
|
|
3
|
-
import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
|
|
4
4
|
interface GetAuthorizerValidatorParams {
|
|
5
5
|
scope?: string;
|
|
6
6
|
type?: AuthClass;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SQSWrapperArgs } from '../types';
|
|
2
|
-
declare const sqsEventWrapper: <RecordType extends
|
|
1
|
+
import { BaseRecord, SQSWrapperArgs } from '../types';
|
|
2
|
+
declare const sqsEventWrapper: <RecordType extends BaseRecord>({ event, context, schema, handler, singleHandler, mode, }: SQSWrapperArgs<RecordType>) => Promise<void>;
|
|
3
3
|
export default sqsEventWrapper;
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spytecgps/lambda-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Lambda Utils",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"lint": "eslint \"./src/**\"",
|
|
9
|
+
"lint-fix": "eslint \"./src/**\" --fix",
|
|
10
|
+
"test": "jest --ci --runInBand --reporters=default --reporters=jest-junit --collectCoverage=true",
|
|
8
11
|
"version": "npm run format && git add -A src",
|
|
9
|
-
"preversion": "npm test",
|
|
10
12
|
"postversion": "git push && git push --tags",
|
|
13
|
+
"prepublishOnly": "npm run lint",
|
|
11
14
|
"prepare": "npm run build",
|
|
12
|
-
"build": "
|
|
13
|
-
"
|
|
14
|
-
"format": "prettier --write \"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"version-publish": "npm version patch && npm publish",
|
|
18
|
-
"copydistfolder": "./scripts/copyDistFolder.sh"
|
|
15
|
+
"build-dev": "webpack --mode=development",
|
|
16
|
+
"build": "webpack --mode=production",
|
|
17
|
+
"format": "prettier --write \"**/*.ts\"",
|
|
18
|
+
"copydistfolder": "./scripts/copyDistFolder.sh",
|
|
19
|
+
"version-publish": "npm version patch && npm publish"
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
@@ -28,39 +29,38 @@
|
|
|
28
29
|
},
|
|
29
30
|
"homepage": "https://github.com/spytecgps/lambda-utils#readme",
|
|
30
31
|
"dependencies": {
|
|
32
|
+
"@spytecgps/sdk-logger": "^1.0.7",
|
|
31
33
|
"@middy/core": "^2.5.7",
|
|
32
34
|
"@middy/http-error-handler": "^2.5.7",
|
|
33
35
|
"@middy/http-response-serializer": "^2.5.7",
|
|
34
36
|
"@middy/input-output-logger": "^2.5.7",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"logform": "^2.4.0",
|
|
39
|
-
"qs": "^6.10.1",
|
|
40
|
-
"winston": "^3.7.2",
|
|
41
|
-
"winston-console-format": "^1.0.8"
|
|
37
|
+
"dayjs": "^1.11.11",
|
|
38
|
+
"joi": "^17.13.0",
|
|
39
|
+
"qs": "^6.10.1"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
44
42
|
"@types/aws-lambda": "^8.10.76",
|
|
45
|
-
"@types/jest": "^
|
|
43
|
+
"@types/jest": "^29.5.12",
|
|
46
44
|
"@types/joi": "^17.2.3",
|
|
47
|
-
"@
|
|
48
|
-
"@typescript-eslint/
|
|
45
|
+
"@types/node": "^16",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
47
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
49
48
|
"aws-sdk": "^2.919.0",
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"eslint-config-
|
|
52
|
-
"eslint-
|
|
53
|
-
"eslint-plugin-
|
|
54
|
-
"eslint-plugin-
|
|
55
|
-
"
|
|
56
|
-
"jest": "^
|
|
57
|
-
"
|
|
58
|
-
"prettier": "^
|
|
59
|
-
"ts-jest": "^
|
|
60
|
-
"ts-loader": "^
|
|
61
|
-
"typescript": "^
|
|
62
|
-
"webpack": "^
|
|
63
|
-
"webpack-cli": "^
|
|
49
|
+
"eslint": "^8.27.0",
|
|
50
|
+
"eslint-config-prettier": "^8.5.0",
|
|
51
|
+
"eslint-plugin-import": "^2.26.0",
|
|
52
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
53
|
+
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
54
|
+
"jest": "^29.7.0",
|
|
55
|
+
"jest-junit": "^16",
|
|
56
|
+
"prettier": "^2.8.8",
|
|
57
|
+
"prettier-eslint": "^16.3.0",
|
|
58
|
+
"ts-jest": "^29.0.3",
|
|
59
|
+
"ts-loader": "^9.5.1",
|
|
60
|
+
"typescript": "^4.9.5",
|
|
61
|
+
"webpack": "^5.72.0",
|
|
62
|
+
"webpack-cli": "^4.9.2",
|
|
63
|
+
"webpack-node-externals": "^3.0.0"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
66
|
"dist/**/*"
|
|
@@ -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;
|
|
@@ -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 ConflictError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(ConflictError, _super);
|
|
19
|
-
function ConflictError() {
|
|
20
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
_this.code = 409;
|
|
22
|
-
_this.statusCode = 409;
|
|
23
|
-
_this.name = 'ConflictError';
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
return ConflictError;
|
|
27
|
-
}(HttpError_1.HttpError));
|
|
28
|
-
exports.default = ConflictError;
|
|
@@ -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 ForbiddenError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(ForbiddenError, _super);
|
|
19
|
-
function ForbiddenError() {
|
|
20
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
_this.code = 403;
|
|
22
|
-
_this.statusCode = 403;
|
|
23
|
-
_this.name = 'ForbiddenError';
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
return ForbiddenError;
|
|
27
|
-
}(HttpError_1.HttpError));
|
|
28
|
-
exports.default = ForbiddenError;
|
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,16 +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.ConflictError = exports.ForbiddenError = 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;
|
|
13
|
-
var ForbiddenError_1 = __importDefault(require("./ForbiddenError"));
|
|
14
|
-
exports.ForbiddenError = ForbiddenError_1.default;
|
|
15
|
-
var ConflictError_1 = __importDefault(require("./ConflictError"));
|
|
16
|
-
exports.ConflictError = ConflictError_1.default;
|
package/dist/logger/logger.d.ts
DELETED
package/dist/logger/logger.js
DELETED
|
@@ -1,51 +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 (localError) { return ({
|
|
10
|
-
label: localError.label,
|
|
11
|
-
level: localError.level,
|
|
12
|
-
message: localError.message,
|
|
13
|
-
stack: localError.stack,
|
|
14
|
-
}); };
|
|
15
|
-
var replacer = function (_key, value) { return (value instanceof Error ? replaceError(value) : value); };
|
|
16
|
-
function getDevFormat() {
|
|
17
|
-
return combine(timestamp(), colorize({ all: true }), padLevels(), winston_console_format_1.consoleFormat({
|
|
18
|
-
showMeta: true,
|
|
19
|
-
metaStrip: [
|
|
20
|
-
'timestamp',
|
|
21
|
-
'service',
|
|
22
|
-
'requestId',
|
|
23
|
-
'x-correlation-id',
|
|
24
|
-
'function',
|
|
25
|
-
'contextUserId',
|
|
26
|
-
'contextUserEmail',
|
|
27
|
-
],
|
|
28
|
-
inspectOptions: {
|
|
29
|
-
depth: Infinity,
|
|
30
|
-
colors: true,
|
|
31
|
-
maxArrayLength: Infinity,
|
|
32
|
-
breakLength: 120,
|
|
33
|
-
compact: Infinity,
|
|
34
|
-
},
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
function getProductionFormat() {
|
|
38
|
-
return combine(errors({ stack: true }), timestamp(), json({ replacer: replacer }));
|
|
39
|
-
}
|
|
40
|
-
function getFormat() {
|
|
41
|
-
if (exports.isTest() || exports.isLocal()) {
|
|
42
|
-
return getDevFormat();
|
|
43
|
-
}
|
|
44
|
-
return getProductionFormat();
|
|
45
|
-
}
|
|
46
|
-
exports.logger = winston_1.createLogger({
|
|
47
|
-
level: exports.isTest() || exports.isLocal() ? 'info' : 'verbose',
|
|
48
|
-
defaultMeta: {},
|
|
49
|
-
format: getFormat(),
|
|
50
|
-
transports: [new winston_1.transports.Console()],
|
|
51
|
-
});
|
|
@@ -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.prototype.hasOwnProperty.call(event, '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();
|