diff --git a/packages/parser/src/schemas/s3.ts b/packages/parser/src/schemas/s3.ts index 07f5a01e3..0505f635b 100644 --- a/packages/parser/src/schemas/s3.ts +++ b/packages/parser/src/schemas/s3.ts @@ -1,4 +1,5 @@ import { z } from 'zod'; +import { JSONStringified } from '../helpers.js'; import { EventBridgeSchema } from './eventbridge.js'; import { SqsRecordSchema } from './sqs.js'; @@ -170,12 +171,15 @@ const S3Schema = z.object({ }); const S3SqsEventNotificationRecordSchema = SqsRecordSchema.extend({ - body: z.string(), + body: JSONStringified(S3Schema), }); /** * Zod schema for S3 -> SQS -> Lambda event notification. * + * Each SQS record’s body field is automatically parsed from a JSON string + * and then validated as an S3 event. + * * @example * ```json * { diff --git a/packages/parser/tests/unit/schema/s3.test.ts b/packages/parser/tests/unit/schema/s3.test.ts index 7afde06cf..2335934d0 100644 --- a/packages/parser/tests/unit/schema/s3.test.ts +++ b/packages/parser/tests/unit/schema/s3.test.ts @@ -196,11 +196,15 @@ describe('Schema: S3', () => { filename: 'sqs-event', }); + const expected = structuredClone(event); + // @ts-expect-error - Modifying the expected result to account for transform + expected.Records[0].body = JSON.parse(expected.Records[0].body); + // Prepare const result = S3SqsEventNotificationSchema.parse(event); // Assess - expect(result).toStrictEqual(event); + expect(result).toStrictEqual(expected); }); it('throws if the S3 event notification SQS event is not valid', () => {