|
| 1 | +/* eslint-disable no-console -- Allowing console logging as this is an example file. */ |
1 | 2 | // Replace me with the actual code for your Lambda function |
2 | 3 | import { Handler } from 'aws-lambda'; |
| 4 | +import { PDMResourceSubmitted } from 'digital-letters-events'; |
| 5 | +import eventValidator from 'digital-letters-events/PDMResourceSubmitted.js'; |
3 | 6 |
|
4 | | -export const handler: Handler = async (event) => { |
5 | | - // eslint-disable-next-line no-console |
| 7 | +export const handler: Handler = async (event: PDMResourceSubmitted) => { |
6 | 8 | console.log('Received event:', event); |
| 9 | + |
| 10 | + // We can build a new PDMResourceSubmitted event object like this: |
| 11 | + const pdmResourceSubmittedEvent: PDMResourceSubmitted = { |
| 12 | + type: 'uk.nhs.notify.digital.letters.pdm.resource.submitted.v1', |
| 13 | + source: |
| 14 | + '/nhs/england/notify/staging/dev-647563337/data-plane/digitalletters/pdm', |
| 15 | + dataschema: |
| 16 | + 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-submitted-data.schema.json', |
| 17 | + specversion: '1.0', |
| 18 | + id: '0249e529-f947-4012-819e-b634eb71be79', |
| 19 | + subject: |
| 20 | + 'customer/7ff8ed41-cd5f-20e4-ef4e-34f96d8cc8ac/75027ace-9b8c-bcfe-866e-6c24242cffc3/q58dnxk5e/4cbek805wwx/yiaw7bl0d/her/1ccb7eb8-c6fe-0a42-279a-2a0e48ff1ca9/zk', |
| 21 | + time: '2025-11-21T16:01:52.268Z', |
| 22 | + datacontenttype: 'application/json', |
| 23 | + traceparent: '00-ee4790eb6821064c645406abe918b3da-3a4e6957ce2a15de-01', |
| 24 | + tracestate: 'nisi quis', |
| 25 | + partitionkey: 'customer-7ff8ed41', |
| 26 | + recordedtime: '2025-11-21T16:01:53.268Z', |
| 27 | + sampledrate: 1, |
| 28 | + sequence: '00000000000350773861', |
| 29 | + severitytext: 'INFO', |
| 30 | + severitynumber: 2, |
| 31 | + dataclassification: 'restricted', |
| 32 | + dataregulation: 'ISO-27001', |
| 33 | + datacategory: 'non-sensitive', |
| 34 | + data: { |
| 35 | + messageReference: 'incididunt Ut aute laborum', |
| 36 | + senderId: 'officia voluptate culpa Ut dolor', |
| 37 | + resourceId: 'a2bcbb42-ab7e-42b6-88d6-74f8d3ca4a09', |
| 38 | + retryCount: 97_903_257, |
| 39 | + }, |
| 40 | + }; |
| 41 | + |
| 42 | + console.log('PDM resource submitted event:', pdmResourceSubmittedEvent); |
| 43 | + |
| 44 | + // We can validate an event like this: |
| 45 | + const isEventValid = eventValidator(event); |
| 46 | + if (isEventValid) { |
| 47 | + console.log('pdmResourceSubmittedEvent is valid!'); |
| 48 | + } else { |
| 49 | + console.error('Validation failure!', eventValidator.errors); |
| 50 | + throw new Error('Event validation failed'); |
| 51 | + } |
| 52 | + |
7 | 53 | return { |
8 | 54 | statusCode: 200, |
9 | 55 | body: 'Event logged', |
|
0 commit comments