@spytecgps/lambda-utils 2.3.0 → 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 -14
- 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 -8
- package/dist/logger/index.d.ts +2 -2
- package/dist/middleware/contextualLogger.d.ts +12 -12
- package/dist/middleware/index.d.ts +23 -23
- 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
package/dist/config/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
export type Env = 'base' | 'local' | 'dev' | 'test' | 'production';
|
|
2
|
-
export type DeepPartial<T> = {
|
|
3
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
4
|
-
};
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const setupEnvConfig: <T>(envConfigs: EnvConfigsParam<T>) => T;
|
|
1
|
+
export type Env = 'base' | 'local' | 'dev' | 'test' | 'production';
|
|
2
|
+
export type DeepPartial<T> = {
|
|
3
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
4
|
+
};
|
|
5
|
+
export type EnvConfigsParam<T> = {
|
|
6
|
+
base: DeepPartial<T>;
|
|
7
|
+
[k: string]: DeepPartial<T>;
|
|
8
|
+
};
|
|
9
|
+
export declare const isLocal: () => boolean;
|
|
10
|
+
export declare const isTest: () => boolean;
|
|
11
|
+
export declare const isDev: () => boolean;
|
|
12
|
+
export declare const isProduction: () => boolean;
|
|
13
|
+
export declare const setupEnvConfig: <T>(envConfigs: EnvConfigsParam<T>) => T;
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
export default class BaseError extends Error {
|
|
2
|
-
code: 500;
|
|
3
|
-
statusCode: 500;
|
|
4
|
-
}
|
|
1
|
+
export default class BaseError extends Error {
|
|
2
|
+
code: 500;
|
|
3
|
+
statusCode: 500;
|
|
4
|
+
}
|
|
@@ -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 default 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 default 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,8 +1,8 @@
|
|
|
1
|
-
import BadRequestError from './BadRequestError';
|
|
2
|
-
import BaseError from './BaseError';
|
|
3
|
-
import ConflictError from './ConflictError';
|
|
4
|
-
import ForbiddenError from './ForbiddenError';
|
|
5
|
-
import HttpError from './HttpError';
|
|
6
|
-
import NotFoundError from './NotFoundError';
|
|
7
|
-
import UnauthorizedError from './UnauthorizedError';
|
|
8
|
-
export { BadRequestError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError, HttpError, BaseError };
|
|
1
|
+
import BadRequestError from './BadRequestError';
|
|
2
|
+
import BaseError from './BaseError';
|
|
3
|
+
import ConflictError from './ConflictError';
|
|
4
|
+
import ForbiddenError from './ForbiddenError';
|
|
5
|
+
import HttpError from './HttpError';
|
|
6
|
+
import NotFoundError from './NotFoundError';
|
|
7
|
+
import UnauthorizedError from './UnauthorizedError';
|
|
8
|
+
export { BadRequestError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError, HttpError, BaseError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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';
|
|
8
|
-
export * from './config';
|
|
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';
|
|
8
|
+
export * from './config';
|
package/dist/logger/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { logger, withRequest } from '@spytecgps/sdk-logger';
|
|
2
|
-
export { logger, withRequest };
|
|
1
|
+
import { logger, withRequest } from '@spytecgps/sdk-logger';
|
|
2
|
+
export { logger, withRequest };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare const contextualLogger: () => {
|
|
2
|
-
before: ({ event, context }: {
|
|
3
|
-
event: any;
|
|
4
|
-
context: any;
|
|
5
|
-
}) => Promise<void>;
|
|
6
|
-
};
|
|
7
|
-
export declare const contextualLoggerMiddleware: {
|
|
8
|
-
before: ({ event, context }: {
|
|
9
|
-
event: any;
|
|
10
|
-
context: any;
|
|
11
|
-
}) => Promise<void>;
|
|
12
|
-
};
|
|
1
|
+
export declare const contextualLogger: () => {
|
|
2
|
+
before: ({ event, context }: {
|
|
3
|
+
event: any;
|
|
4
|
+
context: any;
|
|
5
|
+
}) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const contextualLoggerMiddleware: {
|
|
8
|
+
before: ({ event, context }: {
|
|
9
|
+
event: any;
|
|
10
|
+
context: any;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import rawMiddy from '@middy/core';
|
|
2
|
-
import httpErrorHandler from '@middy/http-error-handler';
|
|
3
|
-
import httpResponseSerializer from '@middy/http-response-serializer';
|
|
4
|
-
import sqsJsonBodyParser from '@middy/sqs-json-body-parser';
|
|
5
|
-
import { Context as LambdaContext } from 'aws-lambda/handler';
|
|
6
|
-
import { MiddyInputHandler } from './types';
|
|
7
|
-
import { validatorMiddleware } from './validation';
|
|
8
|
-
import { warmupMiddleware } from './warmup';
|
|
9
|
-
declare const baseMiddlewares: ({
|
|
10
|
-
before: (request: any) => string;
|
|
11
|
-
} | {
|
|
12
|
-
before: ({ event, context }: {
|
|
13
|
-
event: any;
|
|
14
|
-
context: any;
|
|
15
|
-
}) => Promise<void>;
|
|
16
|
-
} | rawMiddy.MiddlewareObj<any, any, Error, LambdaContext>)[];
|
|
17
|
-
declare const apiGatewayMiddlewares: (rawMiddy.MiddlewareObj<any, any, Error, LambdaContext> | {
|
|
18
|
-
after: (req: any) => void;
|
|
19
|
-
onError: (req: any) => void;
|
|
20
|
-
})[];
|
|
21
|
-
declare const middy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
22
|
-
declare const apiGatewayMiddy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
23
|
-
export { apiGatewayMiddlewares, apiGatewayMiddy, baseMiddlewares, httpErrorHandler, httpResponseSerializer, middy, sqsJsonBodyParser, validatorMiddleware, warmupMiddleware, };
|
|
1
|
+
import rawMiddy from '@middy/core';
|
|
2
|
+
import httpErrorHandler from '@middy/http-error-handler';
|
|
3
|
+
import httpResponseSerializer from '@middy/http-response-serializer';
|
|
4
|
+
import sqsJsonBodyParser from '@middy/sqs-json-body-parser';
|
|
5
|
+
import { Context as LambdaContext } from 'aws-lambda/handler';
|
|
6
|
+
import { MiddyInputHandler } from './types';
|
|
7
|
+
import { validatorMiddleware } from './validation';
|
|
8
|
+
import { warmupMiddleware } from './warmup';
|
|
9
|
+
declare const baseMiddlewares: ({
|
|
10
|
+
before: (request: any) => string;
|
|
11
|
+
} | {
|
|
12
|
+
before: ({ event, context }: {
|
|
13
|
+
event: any;
|
|
14
|
+
context: any;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
} | rawMiddy.MiddlewareObj<any, any, Error, LambdaContext>)[];
|
|
17
|
+
declare const apiGatewayMiddlewares: (rawMiddy.MiddlewareObj<any, any, Error, LambdaContext> | {
|
|
18
|
+
after: (req: any) => void;
|
|
19
|
+
onError: (req: any) => void;
|
|
20
|
+
})[];
|
|
21
|
+
declare const middy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
22
|
+
declare const apiGatewayMiddy: <TEvent, TResult, TContext extends LambdaContext>(handler: MiddyInputHandler<TEvent, TResult, TContext>) => rawMiddy.MiddyfiedHandler<TEvent, TResult, Error, TContext>;
|
|
23
|
+
export { apiGatewayMiddlewares, apiGatewayMiddy, baseMiddlewares, httpErrorHandler, httpResponseSerializer, middy, sqsJsonBodyParser, validatorMiddleware, warmupMiddleware, };
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
export declare const responseWrapperMiddleware: () => {
|
|
2
|
-
after: (req: any) => void;
|
|
3
|
-
onError: (req: any) => void;
|
|
4
|
-
};
|
|
1
|
+
export declare const responseWrapperMiddleware: () => {
|
|
2
|
+
after: (req: any) => void;
|
|
3
|
+
onError: (req: any) => void;
|
|
4
|
+
};
|
|
@@ -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 {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const warmupMiddleware: (opt?: any) => {
|
|
2
|
-
before: (request: any) => string;
|
|
3
|
-
};
|
|
1
|
+
export declare const warmupMiddleware: (opt?: any) => {
|
|
2
|
+
before: (request: any) => string;
|
|
3
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
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 type TasksAccess = 'full' | 'can_complete' | 'read_only' | 'no_access';
|
|
14
|
-
export type BillingMethod = 'credit-card-hubspot' | 'ach-hubspot' | 'credit-card-braintree' | 'ach-braintree' | 'ach-wire' | 'check' | 'dib-sap';
|
|
15
|
-
export type CustomerSegment = 'whale' | 'bass' | 'guppy' | 'guppy-self-serve';
|
|
16
|
-
export interface SpytecAuthContext {
|
|
17
|
-
type: AuthClass;
|
|
18
|
-
userId?: string;
|
|
19
|
-
clientId: number;
|
|
20
|
-
devicesAccess: DevicesAccess;
|
|
21
|
-
boundariesAccess: BoundariesAccess;
|
|
22
|
-
minAccessDate?: string;
|
|
23
|
-
resources: SpytecAuthorizedResources;
|
|
24
|
-
principalId: string;
|
|
25
|
-
scope?: string;
|
|
26
|
-
enterprise?: boolean;
|
|
27
|
-
maintenanceModule?: boolean;
|
|
28
|
-
tasksAccess?: TasksAccess;
|
|
29
|
-
billingMethod?: BillingMethod;
|
|
30
|
-
customerSegment?: CustomerSegment;
|
|
31
|
-
securityGroupTagId?: number;
|
|
32
|
-
}
|
|
33
|
-
export type BaseAPIGatewayEvent = Omit<APIGatewayProxyEventBase<SpytecAuthContext>, 'pathParameters' | 'queryStringParameters' | 'body'>;
|
|
34
|
-
export interface WrapperArgs<E, R> {
|
|
35
|
-
event: APIGatewayProxyEvent;
|
|
36
|
-
context?: APIGatewayEventRequestContext;
|
|
37
|
-
schema?: ObjectSchema<E>;
|
|
38
|
-
handler: Handler<E, R>;
|
|
39
|
-
}
|
|
40
|
-
export type UserAPIHandler<TEvent = APIGatewayProxyWithLambdaAuthorizerEvent<SpytecAuthContext>, TResult = any> = (event: TEvent, context: APIGatewayEventRequestContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
41
|
-
export type ServerAPIHandler<TResult = any> = (event: APIGatewayProxyWithCognitoAuthorizerEvent, context: APIGatewayEventRequestContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
42
|
-
export type Handler<E, R> = (event: E) => Promise<HandlerResponse<R>>;
|
|
43
|
-
export interface HandlerResponse<R> {
|
|
44
|
-
statusCode?: number;
|
|
45
|
-
headers?: {
|
|
46
|
-
[header: string]: boolean | number | string;
|
|
47
|
-
};
|
|
48
|
-
isBase64Encoded?: boolean;
|
|
49
|
-
message?: string;
|
|
50
|
-
data?: R;
|
|
51
|
-
rawResult?: boolean;
|
|
52
|
-
stringifyBody?: boolean;
|
|
53
|
-
}
|
|
54
|
-
export type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
|
|
55
|
-
export interface MessageEvent<RecordType extends BaseRecord> {
|
|
56
|
-
Records: RecordType[];
|
|
57
|
-
}
|
|
58
|
-
export type SQSWrapperArgs<RecordType extends BaseRecord> = {
|
|
59
|
-
event: SQSEvent;
|
|
60
|
-
context?: Context;
|
|
61
|
-
schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
|
|
62
|
-
handler?: (e: MessageEvent<RecordType>) => void | Promise<void>;
|
|
63
|
-
singleHandler?: (record: RecordType) => void | Promise<void>;
|
|
64
|
-
mode?: 'serial' | 'parallel';
|
|
65
|
-
};
|
|
66
|
-
export type SQSWrapperArgsWithReturn<RecordType extends BaseRecord, T> = {
|
|
67
|
-
event: SQSEvent;
|
|
68
|
-
context?: Context;
|
|
69
|
-
schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
|
|
70
|
-
handler?: (e: MessageEvent<RecordType>) => T | Promise<T>;
|
|
71
|
-
singleHandler?: (record: RecordType) => T | Promise<T>;
|
|
72
|
-
mode?: 'serial' | 'parallel';
|
|
73
|
-
};
|
|
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 type TasksAccess = 'full' | 'can_complete' | 'read_only' | 'no_access';
|
|
14
|
+
export type BillingMethod = 'credit-card-hubspot' | 'ach-hubspot' | 'credit-card-braintree' | 'ach-braintree' | 'ach-wire' | 'check' | 'dib-sap';
|
|
15
|
+
export type CustomerSegment = 'whale' | 'bass' | 'guppy' | 'guppy-self-serve';
|
|
16
|
+
export interface SpytecAuthContext {
|
|
17
|
+
type: AuthClass;
|
|
18
|
+
userId?: string;
|
|
19
|
+
clientId: number;
|
|
20
|
+
devicesAccess: DevicesAccess;
|
|
21
|
+
boundariesAccess: BoundariesAccess;
|
|
22
|
+
minAccessDate?: string;
|
|
23
|
+
resources: SpytecAuthorizedResources;
|
|
24
|
+
principalId: string;
|
|
25
|
+
scope?: string;
|
|
26
|
+
enterprise?: boolean;
|
|
27
|
+
maintenanceModule?: boolean;
|
|
28
|
+
tasksAccess?: TasksAccess;
|
|
29
|
+
billingMethod?: BillingMethod;
|
|
30
|
+
customerSegment?: CustomerSegment;
|
|
31
|
+
securityGroupTagId?: number;
|
|
32
|
+
}
|
|
33
|
+
export type BaseAPIGatewayEvent = Omit<APIGatewayProxyEventBase<SpytecAuthContext>, 'pathParameters' | 'queryStringParameters' | 'body'>;
|
|
34
|
+
export interface WrapperArgs<E, R> {
|
|
35
|
+
event: APIGatewayProxyEvent;
|
|
36
|
+
context?: APIGatewayEventRequestContext;
|
|
37
|
+
schema?: ObjectSchema<E>;
|
|
38
|
+
handler: Handler<E, R>;
|
|
39
|
+
}
|
|
40
|
+
export type UserAPIHandler<TEvent = APIGatewayProxyWithLambdaAuthorizerEvent<SpytecAuthContext>, TResult = any> = (event: TEvent, context: APIGatewayEventRequestContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
41
|
+
export type ServerAPIHandler<TResult = any> = (event: APIGatewayProxyWithCognitoAuthorizerEvent, context: APIGatewayEventRequestContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
42
|
+
export type Handler<E, R> = (event: E) => Promise<HandlerResponse<R>>;
|
|
43
|
+
export interface HandlerResponse<R> {
|
|
44
|
+
statusCode?: number;
|
|
45
|
+
headers?: {
|
|
46
|
+
[header: string]: boolean | number | string;
|
|
47
|
+
};
|
|
48
|
+
isBase64Encoded?: boolean;
|
|
49
|
+
message?: string;
|
|
50
|
+
data?: R;
|
|
51
|
+
rawResult?: boolean;
|
|
52
|
+
stringifyBody?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export type BaseRecord = Omit<SQSRecord, 'body' | 'messageAttributes'>;
|
|
55
|
+
export interface MessageEvent<RecordType extends BaseRecord> {
|
|
56
|
+
Records: RecordType[];
|
|
57
|
+
}
|
|
58
|
+
export type SQSWrapperArgs<RecordType extends BaseRecord> = {
|
|
59
|
+
event: SQSEvent;
|
|
60
|
+
context?: Context;
|
|
61
|
+
schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
|
|
62
|
+
handler?: (e: MessageEvent<RecordType>) => void | Promise<void>;
|
|
63
|
+
singleHandler?: (record: RecordType) => void | Promise<void>;
|
|
64
|
+
mode?: 'serial' | 'parallel';
|
|
65
|
+
};
|
|
66
|
+
export type SQSWrapperArgsWithReturn<RecordType extends BaseRecord, T> = {
|
|
67
|
+
event: SQSEvent;
|
|
68
|
+
context?: Context;
|
|
69
|
+
schema?: Joi.ObjectSchema<MessageEvent<RecordType>>;
|
|
70
|
+
handler?: (e: MessageEvent<RecordType>) => T | Promise<T>;
|
|
71
|
+
singleHandler?: (record: RecordType) => T | Promise<T>;
|
|
72
|
+
mode?: 'serial' | 'parallel';
|
|
73
|
+
};
|
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,5 +1,5 @@
|
|
|
1
|
-
import merge from 'deepmerge';
|
|
2
|
-
import { LambdaCache } from './cache';
|
|
3
|
-
export * from './cacheWrapper';
|
|
4
|
-
export * from './timeOut';
|
|
5
|
-
export { LambdaCache, merge };
|
|
1
|
+
import merge from 'deepmerge';
|
|
2
|
+
import { LambdaCache } from './cache';
|
|
3
|
+
export * from './cacheWrapper';
|
|
4
|
+
export * from './timeOut';
|
|
5
|
+
export { LambdaCache, merge };
|
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;
|