UNPKG

@aws-lambda-powertools/parser

Version:
175 lines (174 loc) 5.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SesRecordSchema = exports.SesSchema = void 0; const zod_1 = require("zod"); const SesReceiptVerdict = zod_1.z.object({ status: zod_1.z.enum(['PASS', 'FAIL', 'GRAY', 'PROCESSING_FAILED']), }); const SesReceipt = zod_1.z.object({ timestamp: zod_1.z.iso.datetime(), processingTimeMillis: zod_1.z.number().int().positive(), recipients: zod_1.z.array(zod_1.z.string()), spamVerdict: SesReceiptVerdict, virusVerdict: SesReceiptVerdict, spfVerdict: SesReceiptVerdict, dmarcVerdict: SesReceiptVerdict, dkimVerdict: SesReceiptVerdict, dmarcPolicy: zod_1.z.enum(['none', 'quarantine', 'reject']), action: zod_1.z.object({ type: zod_1.z.enum(['Lambda']), invocationType: zod_1.z.literal('Event'), functionArn: zod_1.z.string(), }), }); const SesMail = zod_1.z.object({ timestamp: zod_1.z.iso.datetime(), source: zod_1.z.string(), messageId: zod_1.z.string(), destination: zod_1.z.array(zod_1.z.string()), headersTruncated: zod_1.z.boolean(), headers: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), value: zod_1.z.string(), })), commonHeaders: zod_1.z.object({ from: zod_1.z.array(zod_1.z.string()), to: zod_1.z.array(zod_1.z.string()), cc: zod_1.z.array(zod_1.z.string()).optional(), bcc: zod_1.z.array(zod_1.z.string()).optional(), sender: zod_1.z.array(zod_1.z.string()).optional(), 'reply-to': zod_1.z.array(zod_1.z.string()).optional(), returnPath: zod_1.z.string(), messageId: zod_1.z.string(), date: zod_1.z.string(), subject: zod_1.z.string(), }), }); const SesMessage = zod_1.z.object({ mail: SesMail, receipt: SesReceipt, }); /** * Zod schema for a SES record from an SES event. */ const SesRecordSchema = zod_1.z.object({ eventSource: zod_1.z.literal('aws:ses'), eventVersion: zod_1.z.string(), ses: SesMessage, }); exports.SesRecordSchema = SesRecordSchema; /** * Zod schema for SES events from AWS. * * @example * ```json * { * "Records": [ * { * "eventVersion": "1.0", * "ses": { * "mail": { * "commonHeaders": { * "from": [ * "Jane Doe <janedoe@example.com>" * ], * "to": [ * "johndoe@example.com" * ], * "returnPath": "janedoe@example.com", * "messageId": "<0123456789example.com>", * "date": "Wed, 7 Oct 2015 12:34:56 -0700", * "subject": "Test Subject" * }, * "source": "janedoe@example.com", * "timestamp": "1970-01-01T00:00:00.000Z", * "destination": [ * "johndoe@example.com" * ], * "headers": [ * { * "name": "Return-Path", * "value": "<janedoe@example.com>" * }, * { * "name": "Received", * "value": "from mailer.example.com (mailer.example.com [203.0.113.1]) by ..." * }, * { * "name": "DKIM-Signature", * "value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=example; ..." * }, * { * "name": "MIME-Version", * "value": "1.0" * }, * { * "name": "From", * "value": "Jane Doe <janedoe@example.com>" * }, * { * "name": "Date", * "value": "Wed, 7 Oct 2015 12:34:56 -0700" * }, * { * "name": "Message-ID", * "value": "<0123456789example.com>" * }, * { * "name": "Subject", * "value": "Test Subject" * }, * { * "name": "To", * "value": "johndoe@example.com" * }, * { * "name": "Content-Type", * "value": "text/plain; charset=UTF-8" * } * ], * "headersTruncated": false, * "messageId": "o3vrnil0e2ic28tr" * }, * "receipt": { * "recipients": [ * "johndoe@example.com" * ], * "timestamp": "1970-01-01T00:00:00.000Z", * "spamVerdict": { * "status": "PASS" * }, * "dkimVerdict": { * "status": "PASS" * }, * "dmarcPolicy": "reject", * "processingTimeMillis": 574, * "action": { * "type": "Lambda", * "invocationType": "Event", * "functionArn": "arn:aws:lambda:us-west-2:012345678912:function:Example" * }, * "dmarcVerdict": { * "status": "PASS" * }, * "spfVerdict": { * "status": "PASS" * }, * "virusVerdict": { * "status": "PASS" * } * } * }, * "eventSource": "aws:ses" * } * ] * } * ``` * * @see {@link SesEvent | SesEvent} * @see {@link https://docs.aws.amazon.com/ses/latest/dg/receiving-email-notifications-examples.html} */ const SesSchema = zod_1.z.object({ Records: zod_1.z.array(SesRecordSchema).nonempty(), }); exports.SesSchema = SesSchema;