@spytecgps/lambda-utils 2.0.2-rc1 → 2.0.2
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/errors/BadRequestError.d.ts +6 -6
- 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 +6 -6
- package/dist/index.d.ts +7 -7
- package/dist/logger/index.d.ts +4 -4
- package/dist/middleware/contextualLogger.d.ts +15 -15
- package/dist/middleware/index.d.ts +12 -12
- package/dist/middleware/ioLogger.d.ts +1 -1
- package/dist/middleware/middleware.test.d.ts +1 -1
- package/dist/middleware/responseWrapper.d.ts +3 -3
- package/dist/middleware/types.d.ts +7 -7
- package/dist/middleware/validation.d.ts +9 -9
- package/dist/types.d.ts +58 -58
- package/dist/utils/cache.d.ts +23 -23
- package/dist/utils/cacheWrapper.d.ts +2 -2
- package/dist/utils/index.d.ts +4 -4
- 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 +4 -4
- package/dist/wrappers/response.d.ts +8 -8
- package/dist/wrappers/sqsEventWrapper.d.ts +3 -3
- package/package.json +3 -4
- package/dist/errors/BadRequestError.js +0 -28
- package/dist/errors/BaseError.d.ts +0 -3
- 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,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class BadRequestError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class BadRequestError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class ConflictError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class ConflictError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class ForbiddenError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class ForbiddenError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,8 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class NotFoundError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class NotFoundError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class UnauthorizedError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class UnauthorizedError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import BadRequestError from './BadRequestError';
|
|
2
|
-
import ConflictError from './ConflictError';
|
|
3
|
-
import ForbiddenError from './ForbiddenError';
|
|
4
|
-
import NotFoundError from './NotFoundError';
|
|
5
|
-
import UnauthorizedError from './UnauthorizedError';
|
|
6
|
-
export { BadRequestError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError };
|
|
1
|
+
import BadRequestError from './BadRequestError';
|
|
2
|
+
import ConflictError from './ConflictError';
|
|
3
|
+
import ForbiddenError from './ForbiddenError';
|
|
4
|
+
import NotFoundError from './NotFoundError';
|
|
5
|
+
import UnauthorizedError from './UnauthorizedError';
|
|
6
|
+
export { BadRequestError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './wrappers';
|
|
2
|
-
export * from './errors';
|
|
3
|
-
export * from './validation';
|
|
4
|
-
export * from './types';
|
|
5
|
-
export * from './middleware';
|
|
6
|
-
export * from './logger';
|
|
7
|
-
export * from './utils';
|
|
1
|
+
export * from './wrappers';
|
|
2
|
+
export * from './errors';
|
|
3
|
+
export * from './validation';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './middleware';
|
|
6
|
+
export * from './logger';
|
|
7
|
+
export * from './utils';
|
package/dist/logger/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withRequest } from '@spytecgps/sdk-logger';
|
|
2
|
-
declare let logger:
|
|
3
|
-
declare const resetLogger: (metadata: any) => HapnLogger;
|
|
4
|
-
export { logger, withRequest, resetLogger };
|
|
1
|
+
import { HapnLogger, withRequest } from '@spytecgps/sdk-logger';
|
|
2
|
+
declare let logger: HapnLogger;
|
|
3
|
+
declare const resetLogger: (metadata: any) => HapnLogger;
|
|
4
|
+
export { logger, withRequest, resetLogger };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapted from https://github.com/FormidableLabs/pino-lambda/blob/master/src/request.ts
|
|
3
|
-
*/
|
|
4
|
-
export declare const contextualLogger: () => {
|
|
5
|
-
before: ({ event, context }: {
|
|
6
|
-
event: any;
|
|
7
|
-
context: any;
|
|
8
|
-
}) => Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
export declare const contextualLoggerMiddleware: {
|
|
11
|
-
before: ({ event, context }: {
|
|
12
|
-
event: any;
|
|
13
|
-
context: any;
|
|
14
|
-
}) => Promise<void>;
|
|
15
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Adapted from https://github.com/FormidableLabs/pino-lambda/blob/master/src/request.ts
|
|
3
|
+
*/
|
|
4
|
+
export declare const contextualLogger: () => {
|
|
5
|
+
before: ({ event, context }: {
|
|
6
|
+
event: any;
|
|
7
|
+
context: any;
|
|
8
|
+
}) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare const contextualLoggerMiddleware: {
|
|
11
|
+
before: ({ event, context }: {
|
|
12
|
+
event: any;
|
|
13
|
+
context: any;
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import rawMiddy from '@middy/core';
|
|
2
|
-
import httpErrorHandler from '@middy/http-error-handler';
|
|
3
|
-
import httpResponseSerializer from '@middy/http-response-serializer';
|
|
4
|
-
import { Context as LambdaContext } from 'aws-lambda/handler';
|
|
5
|
-
import { MiddyInputHandler } from './types';
|
|
6
|
-
import { validatorMiddleware } from './validation';
|
|
7
|
-
declare const apiGatewayMiddlewares: (rawMiddy.MiddlewareObj<any, any, Error, LambdaContext> | {
|
|
8
|
-
after: (req: any) => void;
|
|
9
|
-
})[];
|
|
10
|
-
declare const middy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
11
|
-
declare const apiGatewayMiddy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
12
|
-
export { middy, apiGatewayMiddy, httpErrorHandler, httpResponseSerializer, validatorMiddleware, apiGatewayMiddlewares };
|
|
1
|
+
import rawMiddy from '@middy/core';
|
|
2
|
+
import httpErrorHandler from '@middy/http-error-handler';
|
|
3
|
+
import httpResponseSerializer from '@middy/http-response-serializer';
|
|
4
|
+
import { Context as LambdaContext } from 'aws-lambda/handler';
|
|
5
|
+
import { MiddyInputHandler } from './types';
|
|
6
|
+
import { validatorMiddleware } from './validation';
|
|
7
|
+
declare const apiGatewayMiddlewares: (rawMiddy.MiddlewareObj<any, any, Error, LambdaContext> | {
|
|
8
|
+
after: (req: any) => void;
|
|
9
|
+
})[];
|
|
10
|
+
declare const middy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
11
|
+
declare const apiGatewayMiddy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
12
|
+
export { middy, apiGatewayMiddy, httpErrorHandler, httpResponseSerializer, validatorMiddleware, apiGatewayMiddlewares };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ioLoggerMiddleware: import("@middy/core").MiddlewareObj<any, any, Error, import("aws-lambda").Context>;
|
|
1
|
+
export declare const ioLoggerMiddleware: import("@middy/core").MiddlewareObj<any, any, Error, import("aws-lambda").Context>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const responseWrapperMiddleware: () => {
|
|
2
|
-
after: (req: any) => void;
|
|
3
|
-
};
|
|
1
|
+
export declare const responseWrapperMiddleware: () => {
|
|
2
|
+
after: (req: any) => void;
|
|
3
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { APIGatewayProxyResult, Context as LambdaContext } from 'aws-lambda';
|
|
2
|
-
import { Callback as LambdaCallback } from 'aws-lambda/handler';
|
|
3
|
-
export type MiddyInputPromiseHandler<TEvent, TResult, TContext extends LambdaContext = LambdaContext> = (event: TEvent, context: TContext) => Promise<TResult>;
|
|
4
|
-
export interface APIResult<T = any> extends Omit<APIGatewayProxyResult, 'body'> {
|
|
5
|
-
body: T;
|
|
6
|
-
}
|
|
7
|
-
export type MiddyInputHandler<TEvent, TResult, TContext extends LambdaContext = LambdaContext> = (event: TEvent, context: TContext, callback: LambdaCallback<TResult>) => Promise<TResult>;
|
|
1
|
+
import { APIGatewayProxyResult, Context as LambdaContext } from 'aws-lambda';
|
|
2
|
+
import { Callback as LambdaCallback } from 'aws-lambda/handler';
|
|
3
|
+
export type MiddyInputPromiseHandler<TEvent, TResult, TContext extends LambdaContext = LambdaContext> = (event: TEvent, context: TContext) => Promise<TResult>;
|
|
4
|
+
export interface APIResult<T = any> extends Omit<APIGatewayProxyResult, 'body'> {
|
|
5
|
+
body: T;
|
|
6
|
+
}
|
|
7
|
+
export type MiddyInputHandler<TEvent, TResult, TContext extends LambdaContext = LambdaContext> = (event: TEvent, context: TContext, callback: LambdaCallback<TResult>) => Promise<TResult>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
interface ValidatorOpts {
|
|
3
|
-
schema: Joi.Schema;
|
|
4
|
-
allowUnknown?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare const validatorMiddleware: ({ schema, allowUnknown }: ValidatorOpts) => {
|
|
7
|
-
before: (request: any) => void;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
interface ValidatorOpts {
|
|
3
|
+
schema: Joi.Schema;
|
|
4
|
+
allowUnknown?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const validatorMiddleware: ({ schema, allowUnknown }: ValidatorOpts) => {
|
|
7
|
+
before: (request: any) => void;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { APIGatewayEventRequestContext, APIGatewayProxyEvent, APIGatewayProxyWithCognitoAuthorizerEvent, APIGatewayProxyWithLambdaAuthorizerEvent, Context, SQSEvent, SQSRecord } from 'aws-lambda';
|
|
2
|
-
import { Callback } from 'aws-lambda/handler';
|
|
3
|
-
import { APIGatewayProxyEventBase } from 'aws-lambda/trigger/api-gateway-proxy';
|
|
4
|
-
import { ObjectSchema } from 'joi';
|
|
5
|
-
import * as Joi from 'joi';
|
|
6
|
-
export interface SpytecAuthorizedResources {
|
|
7
|
-
devices: string[];
|
|
8
|
-
boundaries: number[];
|
|
9
|
-
}
|
|
10
|
-
export type AuthClass = 'user' | 'client' | 'system';
|
|
11
|
-
export type DevicesAccess = 'full' | 'limited';
|
|
12
|
-
export type BoundariesAccess = 'full' | 'limited';
|
|
13
|
-
export interface SpytecAuthContext {
|
|
14
|
-
type: AuthClass;
|
|
15
|
-
userId?: string;
|
|
16
|
-
clientId: number;
|
|
17
|
-
devicesAccess: DevicesAccess;
|
|
18
|
-
boundariesAccess: BoundariesAccess;
|
|
19
|
-
minAccessDate?: string;
|
|
20
|
-
resources: SpytecAuthorizedResources;
|
|
21
|
-
principalId: string;
|
|
22
|
-
scope?: string;
|
|
23
|
-
enterprise?: boolean;
|
|
24
|
-
maintenanceModule?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export type BaseAPIGatewayEvent = Omit<APIGatewayProxyEventBase<SpytecAuthContext>, 'pathParameters' | 'queryStringParameters' | 'body'>;
|
|
27
|
-
export interface WrapperArgs<E, R> {
|
|
28
|
-
event: APIGatewayProxyEvent;
|
|
29
|
-
context?: APIGatewayEventRequestContext;
|
|
30
|
-
schema?: ObjectSchema<E>;
|
|
31
|
-
handler: Handler<E, R>;
|
|
32
|
-
}
|
|
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
|
-
export interface HandlerResponse<R> {
|
|
37
|
-
statusCode?: number;
|
|
38
|
-
headers?: {
|
|
39
|
-
[header: string]: boolean | number | string;
|
|
40
|
-
};
|
|
41
|
-
isBase64Encoded?: boolean;
|
|
42
|
-
message?: string;
|
|
43
|
-
data?: R;
|
|
44
|
-
rawResult?: boolean;
|
|
45
|
-
stringifyBody?: boolean;
|
|
46
|
-
}
|
|
47
|
-
export type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
|
|
48
|
-
export interface MessageEvent<RecordType extends BaseRecord> {
|
|
49
|
-
Records: RecordType[];
|
|
50
|
-
}
|
|
51
|
-
export type SQSWrapperArgs<RecordType extends BaseRecord> = {
|
|
52
|
-
event: SQSEvent;
|
|
53
|
-
context?: Context;
|
|
54
|
-
schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
|
|
55
|
-
handler?: (e: MessageEvent<RecordType>) => void | Promise<void>;
|
|
56
|
-
singleHandler?: (record: RecordType) => void | Promise<void>;
|
|
57
|
-
mode?: 'serial' | 'parallel';
|
|
58
|
-
};
|
|
1
|
+
import { APIGatewayEventRequestContext, APIGatewayProxyEvent, APIGatewayProxyWithCognitoAuthorizerEvent, APIGatewayProxyWithLambdaAuthorizerEvent, Context, SQSEvent, SQSRecord } from 'aws-lambda';
|
|
2
|
+
import { Callback } from 'aws-lambda/handler';
|
|
3
|
+
import { APIGatewayProxyEventBase } from 'aws-lambda/trigger/api-gateway-proxy';
|
|
4
|
+
import { ObjectSchema } from 'joi';
|
|
5
|
+
import * as Joi from 'joi';
|
|
6
|
+
export interface SpytecAuthorizedResources {
|
|
7
|
+
devices: string[];
|
|
8
|
+
boundaries: number[];
|
|
9
|
+
}
|
|
10
|
+
export type AuthClass = 'user' | 'client' | 'system';
|
|
11
|
+
export type DevicesAccess = 'full' | 'limited';
|
|
12
|
+
export type BoundariesAccess = 'full' | 'limited';
|
|
13
|
+
export interface SpytecAuthContext {
|
|
14
|
+
type: AuthClass;
|
|
15
|
+
userId?: string;
|
|
16
|
+
clientId: number;
|
|
17
|
+
devicesAccess: DevicesAccess;
|
|
18
|
+
boundariesAccess: BoundariesAccess;
|
|
19
|
+
minAccessDate?: string;
|
|
20
|
+
resources: SpytecAuthorizedResources;
|
|
21
|
+
principalId: string;
|
|
22
|
+
scope?: string;
|
|
23
|
+
enterprise?: boolean;
|
|
24
|
+
maintenanceModule?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type BaseAPIGatewayEvent = Omit<APIGatewayProxyEventBase<SpytecAuthContext>, 'pathParameters' | 'queryStringParameters' | 'body'>;
|
|
27
|
+
export interface WrapperArgs<E, R> {
|
|
28
|
+
event: APIGatewayProxyEvent;
|
|
29
|
+
context?: APIGatewayEventRequestContext;
|
|
30
|
+
schema?: ObjectSchema<E>;
|
|
31
|
+
handler: Handler<E, R>;
|
|
32
|
+
}
|
|
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
|
+
export interface HandlerResponse<R> {
|
|
37
|
+
statusCode?: number;
|
|
38
|
+
headers?: {
|
|
39
|
+
[header: string]: boolean | number | string;
|
|
40
|
+
};
|
|
41
|
+
isBase64Encoded?: boolean;
|
|
42
|
+
message?: string;
|
|
43
|
+
data?: R;
|
|
44
|
+
rawResult?: boolean;
|
|
45
|
+
stringifyBody?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
|
|
48
|
+
export interface MessageEvent<RecordType extends BaseRecord> {
|
|
49
|
+
Records: RecordType[];
|
|
50
|
+
}
|
|
51
|
+
export type SQSWrapperArgs<RecordType extends BaseRecord> = {
|
|
52
|
+
event: SQSEvent;
|
|
53
|
+
context?: Context;
|
|
54
|
+
schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
|
|
55
|
+
handler?: (e: MessageEvent<RecordType>) => void | Promise<void>;
|
|
56
|
+
singleHandler?: (record: RecordType) => void | Promise<void>;
|
|
57
|
+
mode?: 'serial' | 'parallel';
|
|
58
|
+
};
|
package/dist/utils/cache.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export declare class LambdaCache {
|
|
2
|
-
private collectionName;
|
|
3
|
-
/**
|
|
4
|
-
* @param {String} collectionName (not required) - The collection key used to store the cache values.
|
|
5
|
-
* If not provide default collection name uses :
|
|
6
|
-
* ${process.env.AWS_LAMBDA_FUNCTION_NAME}-${process.env.AWS_LAMBDA_FUNCTION_VERSION}
|
|
7
|
-
* */
|
|
8
|
-
constructor(collectionName?: string);
|
|
9
|
-
/**
|
|
10
|
-
* @param {String} key (required) - cache key
|
|
11
|
-
* @param {Object} value (required) - cache value
|
|
12
|
-
* @param {Number} expire (required) - cache expiration time (seconds)
|
|
13
|
-
* */
|
|
14
|
-
set(key: string, value: unknown, ttl: number): void;
|
|
15
|
-
/**
|
|
16
|
-
* @param {String} key (required) - cache key to get
|
|
17
|
-
* */
|
|
18
|
-
get(key: string): unknown;
|
|
19
|
-
/**
|
|
20
|
-
* @param {String} key (required) - cache key to remove
|
|
21
|
-
* */
|
|
22
|
-
remove(key: any): void;
|
|
23
|
-
}
|
|
1
|
+
export declare class LambdaCache {
|
|
2
|
+
private collectionName;
|
|
3
|
+
/**
|
|
4
|
+
* @param {String} collectionName (not required) - The collection key used to store the cache values.
|
|
5
|
+
* If not provide default collection name uses :
|
|
6
|
+
* ${process.env.AWS_LAMBDA_FUNCTION_NAME}-${process.env.AWS_LAMBDA_FUNCTION_VERSION}
|
|
7
|
+
* */
|
|
8
|
+
constructor(collectionName?: string);
|
|
9
|
+
/**
|
|
10
|
+
* @param {String} key (required) - cache key
|
|
11
|
+
* @param {Object} value (required) - cache value
|
|
12
|
+
* @param {Number} expire (required) - cache expiration time (seconds)
|
|
13
|
+
* */
|
|
14
|
+
set(key: string, value: unknown, ttl: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* @param {String} key (required) - cache key to get
|
|
17
|
+
* */
|
|
18
|
+
get(key: string): unknown;
|
|
19
|
+
/**
|
|
20
|
+
* @param {String} key (required) - cache key to remove
|
|
21
|
+
* */
|
|
22
|
+
remove(key: any): void;
|
|
23
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LambdaCache } from './cache';
|
|
2
|
-
export declare const promiseWithCache: <T>(promise: () => Promise<T>, cacheInstance: LambdaCache, cacheKey: string, ttl: number) => Promise<T>;
|
|
1
|
+
import { LambdaCache } from './cache';
|
|
2
|
+
export declare const promiseWithCache: <T>(promise: () => Promise<T>, cacheInstance: LambdaCache, cacheKey: string, ttl: number) => Promise<T>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LambdaCache } from './cache';
|
|
2
|
-
export * from './cacheWrapper';
|
|
3
|
-
export * from './timeOut';
|
|
4
|
-
export { LambdaCache };
|
|
1
|
+
import { LambdaCache } from './cache';
|
|
2
|
+
export * from './cacheWrapper';
|
|
3
|
+
export * from './timeOut';
|
|
4
|
+
export { LambdaCache };
|
package/dist/utils/timeOut.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const promiseWithTimeout: <T>(promise: Promise<T>, ms: number, timeoutError?: Error) => Promise<T>;
|
|
1
|
+
export declare const promiseWithTimeout: <T>(promise: Promise<T>, ms: number, timeoutError?: Error) => Promise<T>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import * as Joi from 'joi';
|
|
2
|
-
import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
|
|
3
|
-
export declare const json: any;
|
|
4
|
-
export declare const urlEncoded: any;
|
|
5
|
-
export declare const imeiSchema: Joi.StringSchema<string>;
|
|
6
|
-
export declare const iccidSchema: Joi.StringSchema<string>;
|
|
7
|
-
interface SpytecJoi extends Joi.Root {
|
|
8
|
-
urlEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
|
|
9
|
-
jsonObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
|
|
10
|
-
imei(): StringSchema;
|
|
11
|
-
iccid(): StringSchema;
|
|
12
|
-
delimitedArray(): ArraySchema;
|
|
13
|
-
dateString(): StringSchema;
|
|
14
|
-
jsonArray<TSchema = any, T = TSchema>(schema?: Joi.SchemaMap<T>): ArraySchema<TSchema>;
|
|
15
|
-
base64ThenUriEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
|
|
16
|
-
}
|
|
17
|
-
export declare const SpytecJoi: SpytecJoi;
|
|
18
|
-
export {};
|
|
1
|
+
import * as Joi from 'joi';
|
|
2
|
+
import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
|
|
3
|
+
export declare const json: any;
|
|
4
|
+
export declare const urlEncoded: any;
|
|
5
|
+
export declare const imeiSchema: Joi.StringSchema<string>;
|
|
6
|
+
export declare const iccidSchema: Joi.StringSchema<string>;
|
|
7
|
+
interface SpytecJoi extends Joi.Root {
|
|
8
|
+
urlEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
|
|
9
|
+
jsonObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
|
|
10
|
+
imei(): StringSchema;
|
|
11
|
+
iccid(): StringSchema;
|
|
12
|
+
delimitedArray(): ArraySchema;
|
|
13
|
+
dateString(): StringSchema;
|
|
14
|
+
jsonArray<TSchema = any, T = TSchema>(schema?: Joi.SchemaMap<T>): ArraySchema<TSchema>;
|
|
15
|
+
base64ThenUriEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
|
|
16
|
+
}
|
|
17
|
+
export declare const SpytecJoi: SpytecJoi;
|
|
18
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseAPIGatewayEvent } from '../types';
|
|
2
|
-
import validateEvent from './validateEvent';
|
|
3
|
-
export { validateEvent };
|
|
4
|
-
export * from './custom';
|
|
5
|
-
export * from './requestContext';
|
|
6
|
-
export declare const defaultApiSchema: import("joi").ObjectSchema<BaseAPIGatewayEvent>;
|
|
1
|
+
import { BaseAPIGatewayEvent } from '../types';
|
|
2
|
+
import validateEvent from './validateEvent';
|
|
3
|
+
export { validateEvent };
|
|
4
|
+
export * from './custom';
|
|
5
|
+
export * from './requestContext';
|
|
6
|
+
export declare const defaultApiSchema: import("joi").ObjectSchema<BaseAPIGatewayEvent>;
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import apiGatewayEventWrapper from './apiGatewayEventWrapper';
|
|
2
|
-
import sqsEventWrapper from './sqsEventWrapper';
|
|
3
|
-
export { apiGatewayEventWrapper, sqsEventWrapper };
|
|
4
|
-
export * from './response';
|
|
1
|
+
import apiGatewayEventWrapper from './apiGatewayEventWrapper';
|
|
2
|
+
import sqsEventWrapper from './sqsEventWrapper';
|
|
3
|
+
export { apiGatewayEventWrapper, sqsEventWrapper };
|
|
4
|
+
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spytecgps/lambda-utils",
|
|
3
|
-
"version": "2.0.2
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Lambda Utils",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/spytecgps/lambda-utils#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@spytecgps/sdk-logger": "^2.0.0-rc8",
|
|
33
32
|
"@middy/core": "^2.5.7",
|
|
34
33
|
"@middy/http-error-handler": "^2.5.7",
|
|
35
34
|
"@middy/http-response-serializer": "^2.5.7",
|
|
36
35
|
"@middy/input-output-logger": "^2.5.7",
|
|
36
|
+
"@spytecgps/sdk-logger": "^1.0.7",
|
|
37
37
|
"dayjs": "^1.11.11",
|
|
38
38
|
"joi": "^17.13.0",
|
|
39
39
|
"qs": "^6.10.1"
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"@types/node": "^16",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
47
47
|
"@typescript-eslint/parser": "^5.42.1",
|
|
48
|
-
"aws-sdk": "^2.919.0",
|
|
49
48
|
"eslint": "^8.27.0",
|
|
50
49
|
"eslint-config-prettier": "^8.5.0",
|
|
51
50
|
"eslint-plugin-import": "^2.26.0",
|
|
@@ -65,4 +64,4 @@
|
|
|
65
64
|
"files": [
|
|
66
65
|
"dist/**/*"
|
|
67
66
|
]
|
|
68
|
-
}
|
|
67
|
+
}
|
|
@@ -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;
|