UNPKG

@energica-city/shared-amplify-utils

Version:

Shared utilities for AWS Amplify projects

59 lines 2.78 kB
import type { RestInputWithModels, RestEvent } from './types'; import type { AmplifyModelType, QueryFactoryResult } from '../../queries/types'; import type { RestResponse } from './types'; /** * Build standardized log context for REST operations */ export declare function buildRestContext<TTypes extends Record<string, AmplifyModelType> = Record<string, AmplifyModelType>, TSelected extends keyof TTypes = keyof TTypes>(input: RestInputWithModels<TTypes, TSelected>, additionalContext?: Record<string, unknown>): Record<string, unknown>; /** * Extract basic event information for logging */ export declare function extractEventInfo(event: RestEvent): Record<string, unknown>; /** * Setup structured logging for REST middleware */ export declare function setupStructuredLogging<TTypes extends Record<string, AmplifyModelType> = Record<string, AmplifyModelType>, TSelected extends keyof TTypes = keyof TTypes>(input: RestInputWithModels<TTypes, TSelected>, forceStructuredLogging?: boolean, defaultContext?: Record<string, unknown>): void; /** * Extract error message safely */ export declare function getErrorMessage(error: unknown): string; /** * Get error stack trace if available */ export declare function getErrorStack(error: unknown): string | undefined; /** * Safely parses JSON body with error handling and logging */ export declare function parseJsonBody(body: string | undefined, context: Record<string, unknown>): unknown; /** * Extracts request ID from multiple possible sources */ export declare function getRequestId(event: RestEvent, context?: { awsRequestId?: string; }): string; /** * Build error context with REST information */ export declare function buildErrorContext<TTypes extends Record<string, AmplifyModelType> = Record<string, AmplifyModelType>, TSelected extends keyof TTypes = keyof TTypes>(input: RestInputWithModels<TTypes, TSelected>, error: { code?: string; statusCode?: number; } | null, additionalContext?: Record<string, unknown>): Record<string, unknown>; export declare function getModelsFromInput<TTypes extends Record<string, AmplifyModelType>, TSelected extends keyof TTypes = keyof TTypes>(input: RestInputWithModels<TTypes, TSelected>): { [K in TSelected]: QueryFactoryResult<K & string, TTypes>; }; export declare function createSuccessResponse(payload?: unknown, options?: { statusCode?: number; headers?: Record<string, string>; isBase64Encoded?: boolean; }): RestResponse; /** * Create a standard API Gateway error response */ export declare function createErrorResponse(message: string, options?: { statusCode?: number; code?: string; details?: unknown; headers?: Record<string, string>; isBase64Encoded?: boolean; }): RestResponse; //# sourceMappingURL=utils.d.ts.map