diff --git a/packages/parser/src/envelopes/kafka.ts b/packages/parser/src/envelopes/kafka.ts index 32529d4255..86eb44063f 100644 --- a/packages/parser/src/envelopes/kafka.ts +++ b/packages/parser/src/envelopes/kafka.ts @@ -4,7 +4,6 @@ import { KafkaMskEventSchema, KafkaSelfManagedEventSchema, } from '../schemas/kafka.js'; -import { type KafkaRecord } from '../types/schema.js'; /** * Kafka event envelope to extract data within body key @@ -32,7 +31,7 @@ export const kafkaEnvelope = ( : KafkaSelfManagedEventSchema.parse(data); return Object.values(parsedEnvelope.records).map((topicRecord) => { - return topicRecord.map((record: KafkaRecord) => { + return topicRecord.map((record) => { return parse(record.value, schema); }); }); diff --git a/packages/parser/src/types/schema.ts b/packages/parser/src/types/schema.ts index cc5869a1e2..6e15f17bd0 100644 --- a/packages/parser/src/types/schema.ts +++ b/packages/parser/src/types/schema.ts @@ -1,17 +1,120 @@ -import { KafkaRecordSchema } from '../schemas/kafka.js'; +import { + KafkaSelfManagedEventSchema, + KafkaMskEventSchema, +} from '../schemas/kafka.js'; import { z } from 'zod'; import { KinesisDataStreamRecord, KinesisDataStreamRecordPayload, + KinesisDataStreamSchema, } from '../schemas/kinesis.js'; import { APIGatewayProxyEventSchema } from '../schemas/apigw.js'; +import { AlbSchema, AlbMultiValueHeadersSchema } from '../schemas/alb.js'; +import { APIGatewayProxyEventV2Schema } from '../schemas/apigwv2.js'; +import { DynamoDBStreamSchema } from '../schemas/dynamodb.js'; +import { SqsSchema } from '../schemas/sqs.js'; +import { + CloudFormationCustomResourceCreateSchema, + CloudFormationCustomResourceDeleteSchema, + CloudFormationCustomResourceUpdateSchema, +} from '../schemas/cloudformation-custom-resource.js'; +import { CloudWatchLogsSchema } from '../schemas/cloudwatch.js'; +import { EventBridgeSchema } from '../schemas/eventbridge.js'; +import { + KinesisFirehoseSchema, + KinesisFirehoseSqsSchema, +} from '../schemas/kinesis-firehose.js'; +import { LambdaFunctionUrlSchema } from '../schemas/lambda.js'; +import { + S3EventNotificationEventBridgeSchema, + S3Schema, + S3SqsEventNotificationSchema, +} from '../schemas/s3.js'; +import { SesSchema } from '../schemas/ses.js'; +import { SnsSchema } from '../schemas/sns.js'; +import { VpcLatticeSchema } from '../schemas/vpc-lattice.js'; +import { VpcLatticeV2Schema } from '../schemas/vpc-latticev2.js'; + +type ALBEvent = z.infer; + +type ALBMultiValueHeadersEvent = z.infer; + +type APIGatewayProxyEvent = z.infer; +type APIGatewayProxyEventV2 = z.infer; -export type KafkaRecord = z.infer; +type CloudFormationCustomResourceCreateEvent = z.infer< + typeof CloudFormationCustomResourceCreateSchema +>; -export type KinesisDataStreamRecord = z.infer; +type CloudFormationCustomResourceDeleteEvent = z.infer< + typeof CloudFormationCustomResourceDeleteSchema +>; -export type KinesisDataStreamRecordPayload = z.infer< - typeof KinesisDataStreamRecordPayload +type CloudFormationCustomResourceUpdateEvent = z.infer< + typeof CloudFormationCustomResourceUpdateSchema >; -export type ApiGatewayProxyEvent = z.infer; +type CloudWatchLogsEvent = z.infer; + +type DynamoDBStreamEvent = z.infer; + +type EventBridgeEvent = z.infer; + +type KafkaSelfManagedEvent = z.infer; + +type KafkaMskEvent = z.infer; + +type KinesisDataStreamEvent = z.infer; + +type KinesisFireHoseEvent = z.infer; + +type KinesisFireHoseSqsEvent = z.infer; + +type LambdaFunctionUrlEvent = z.infer; + +type S3Event = z.infer; + +type S3EventNotificationEventBridge = z.infer< + typeof S3EventNotificationEventBridgeSchema +>; + +type S3SqsEventNotification = z.infer; + +type SesEvent = z.infer; + +type SnsEvent = z.infer; + +type SqsEvent = z.infer; + +type VpcLatticeEvent = z.infer; + +type VpcLatticeEventV2 = z.infer; + +export { + type ALBEvent, + type ALBMultiValueHeadersEvent, + type APIGatewayProxyEvent, + type APIGatewayProxyEventV2, + type CloudFormationCustomResourceCreateEvent, + type CloudFormationCustomResourceDeleteEvent, + type CloudFormationCustomResourceUpdateEvent, + type CloudWatchLogsEvent, + type DynamoDBStreamEvent, + type EventBridgeEvent, + type KafkaSelfManagedEvent, + type KafkaMskEvent, + type KinesisDataStreamEvent, + type KinesisDataStreamRecord, + type KinesisDataStreamRecordPayload, + type KinesisFireHoseEvent, + type KinesisFireHoseSqsEvent, + type LambdaFunctionUrlEvent, + type S3Event, + type S3EventNotificationEventBridge, + type S3SqsEventNotification, + type SesEvent, + type SnsEvent, + type SqsEvent, + type VpcLatticeEvent, + type VpcLatticeEventV2, +}; diff --git a/packages/parser/tests/unit/envelopes/apigwt.test.ts b/packages/parser/tests/unit/envelopes/apigwt.test.ts index 6c51736b16..b50e18b439 100644 --- a/packages/parser/tests/unit/envelopes/apigwt.test.ts +++ b/packages/parser/tests/unit/envelopes/apigwt.test.ts @@ -6,13 +6,13 @@ import { generateMock } from '@anatine/zod-mock'; import { TestEvents, TestSchema } from '../schema/utils.js'; -import { ApiGatewayProxyEvent } from '../../../src/types/schema.js'; +import { APIGatewayProxyEvent } from '../../../src/types/schema.js'; import { apiGatewayEnvelope } from '../../../src/envelopes/apigw'; describe('ApigwEnvelope ', () => { it('should parse custom schema in envelope', () => { const testCustomSchemaObject = generateMock(TestSchema); - const testEvent = TestEvents.apiGatewayProxyEvent as ApiGatewayProxyEvent; + const testEvent = TestEvents.apiGatewayProxyEvent as APIGatewayProxyEvent; testEvent.body = JSON.stringify(testCustomSchemaObject); @@ -21,7 +21,7 @@ describe('ApigwEnvelope ', () => { }); it('should throw no body provided', () => { - const testEvent = TestEvents.apiGatewayProxyEvent as ApiGatewayProxyEvent; + const testEvent = TestEvents.apiGatewayProxyEvent as APIGatewayProxyEvent; testEvent.body = undefined; expect(() => apiGatewayEnvelope(testEvent, TestSchema)).toThrow();