Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@leanstacks/serverless-common",
"version": "1.2.0",
"version": "1.3.0-alpha.2",
"description": "LeanStacks organization common serverless components.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
54 changes: 52 additions & 2 deletions src/utils/middyfy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import httpEventNormalizer from '@middy/http-event-normalizer';
import jsonBodyParser from '@middy/http-json-body-parser';
import {
APIGatewayProxyEvent,
APIGatewayProxyEventBase,
APIGatewayProxyEventPathParameters,
APIGatewayProxyEventQueryStringParameters,
APIGatewayProxyResult,
Context,
ScheduledEvent,
Expand All @@ -16,11 +19,58 @@ import { loggerInitializer } from '../middlewares/logger-initializer';
import { validator } from '../middlewares/validator-joi';
import { httpErrorHandler } from '../middlewares/error-handler-http';

/**
* An API Gateway authorizer context for requests authorized with the
* LeanStacks client token.
*/
export type LSAPIClientAuthorizerContext = {
preferred_username: string;
};

/**
* An API Gateway authorizer context for requests authorized with a
* Cognito token.
*/
export type LSCognitoAuthorizerContext = {
email: string;
family_name: string;
given_name: string;
permissions: {
[teamId: string]: string[];
};
preferred_username: string;
user_id: string;
};

/**
* An API Gateway event which has been normalized by middleware.
* @template TAuthorizerContext - The authorizer context type.
* @template TBody - Optional. The body type. Default: `null`.
* @template TPathParameters - Optional. The path parameters type. Default: `APIGatewayProxyEventPathParameters`.
* @template TQueryString - Optional. The query string parameters type. Default: `APIGatewayProxyEventQueryStringParameters`.
* @see {@link APIGatewayProxyEventBase}
* @see {@link APIGatewayProxyEventPathParameters}
* @see {@link APIGatewayProxyEventQueryStringParameters}
*/
export type NormalizedAPIGatewayProxyEvent<
TAuthorizerContext,
TBody = null,
TPathParameters = APIGatewayProxyEventPathParameters,
TQueryString = APIGatewayProxyEventQueryStringParameters,
> = Omit<
APIGatewayProxyEventBase<TAuthorizerContext>,
'body' | 'pathParameters' | 'queryStringParameters'
> & {
body: TBody;
pathParameters: TPathParameters;
queryStringParameters: TQueryString;
};

/**
* The AWS Lambda handler function signature for API Gateway proxy events.
*/
export type APIGatewayHandlerFn = (
event: APIGatewayProxyEvent,
export type APIGatewayHandlerFn<TEvent = APIGatewayProxyEvent> = (
event: TEvent,
context: Context,
) => Promise<APIGatewayProxyResult>;

Expand Down