@energica-city/shared-amplify-utils
Version:
Shared utilities for AWS Amplify projects
96 lines • 3.66 kB
TypeScript
import type { Context, APIGatewayProxyEvent } from 'aws-lambda';
import type { Middleware, MiddlewareChain } from '../middlewareChain';
import type { AmplifyOutputs, AmplifyModelType, QueryFactoryResult } from '../../queries/types';
import type * as yup from 'yup';
export interface MiddlewareError extends Error {
middlewareName?: string;
middlewareIndex?: number;
totalMiddlewares?: number;
middlewareChain?: string[];
}
export type WebSocketEvent = Omit<APIGatewayProxyEvent, 'body'> & {
requestContext: APIGatewayProxyEvent['requestContext'] & {
connectionId: string;
routeKey: string;
messageId?: string;
eventType: 'CONNECT' | 'DISCONNECT' | 'MESSAGE';
};
body?: string;
};
export interface WebSocketResponse {
statusCode: number;
headers?: Record<string, string>;
body: string;
isBase64Encoded?: boolean;
}
export type WebSocketModelInstance<T extends string = string, Types extends Record<T, AmplifyModelType> = Record<T, AmplifyModelType>> = QueryFactoryResult<T, Types>;
export interface WebSocketBaseInput {
event: WebSocketEvent;
context: Context;
}
export interface WebSocketInputWithModels<TTypes extends Record<string, AmplifyModelType> = Record<string, AmplifyModelType>> extends WebSocketBaseInput {
models?: {
[K in keyof TTypes]: QueryFactoryResult<K & string, TTypes>;
};
}
export interface IAMPolicyStatement {
Effect: 'Allow' | 'Deny';
Action: string | string[];
Resource: string | string[];
Condition?: Record<string, unknown>;
}
export interface IAMPolicyDocument {
Version: string;
Statement: IAMPolicyStatement[];
}
export interface AuthorizerResponse {
principalId: string;
policyDocument: IAMPolicyDocument;
context?: Record<string, string | number | boolean>;
usageIdentifierKey?: string;
}
export type WebSocketHandlerReturn = WebSocketResponse | AuthorizerResponse;
export type WebSocketMiddlewareChain<TTypes extends Record<string, AmplifyModelType> = Record<string, AmplifyModelType>, TReturn = WebSocketHandlerReturn> = MiddlewareChain<WebSocketInputWithModels<TTypes>, TReturn>;
export type WebSocketMiddleware<TTypes extends Record<string, AmplifyModelType> = Record<string, AmplifyModelType>, TReturn = WebSocketHandlerReturn> = Middleware<WebSocketInputWithModels<TTypes>, TReturn>;
export interface WebSocketModelInitializerConfig<TSchema extends {
models: Record<string, unknown>;
}, TTypes extends Record<string, AmplifyModelType>> {
schema: TSchema;
amplifyOutputs: AmplifyOutputs;
entities?: (keyof TTypes & string)[];
clientKey?: string;
timeout?: number;
}
export interface WebSocketRequestLoggerConfig {
logEvent?: boolean;
logResponse?: boolean;
logTiming?: boolean;
maxDepth?: number;
excludeEventFields?: string[];
excludeResponseFields?: string[];
defaultContext?: Record<string, unknown>;
logLevel?: 'debug' | 'info' | 'warn' | 'error';
logMessageBody?: boolean;
forceStructuredLogging?: boolean;
}
export interface WebSocketErrorHandlerConfig {
includeStackTrace?: boolean;
defaultContext?: Record<string, unknown>;
forceStructuredLogging?: boolean;
}
export interface WebSocketRequestValidationConfig {
bodySchema?: yup.Schema;
stripUnknown?: boolean;
abortEarly?: boolean;
errorMessage?: string;
errorContext?: Record<string, unknown>;
validateOnlyOnRoutes?: string[];
logValidationSkipped?: boolean;
}
export interface ValidationErrorDetail {
field: string;
message: string;
value: unknown;
type: string;
}
//# sourceMappingURL=types.d.ts.map