Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): add Cognito pre-signup trigger schema #3729

Merged

Conversation

VatsalGoel3
Copy link
Contributor

@VatsalGoel3 VatsalGoel3 commented Mar 17, 2025

Summary

Changes

This PR adds comprehensive Cognito trigger schemas to the Parser utility. The new schemas are implemented using Zod and ensure that AWS Cognito Lambda triggers conform to the expected event structures. The updates cover all 12 trigger types, including:

Pre-Signup Trigger: Validates events when users sign up.
Post-Confirmation Trigger: Validates events after user confirmation.
Pre-Authentication Trigger: Validates events prior to authentication.
Post-Authentication Trigger: Validates events after authentication.
Pre-Token Generation Trigger (V1 & V2): Validates events before token generation.
Migrate User Trigger: Validates events for user migration during sign-in or forgot-password flows.
Custom Message Trigger: Validates events for custom message modifications.
Custom Email Sender Trigger: Validates events for custom email sender functions (with an empty response object).
Custom SMS Sender Trigger: Validates events for custom SMS sender functions.
Define Auth Challenge Trigger: Validates events for initiating a custom auth challenge flow.
Create Auth Challenge Trigger: Validates events that create challenge details for custom authentication.
Verify Auth Challenge Trigger: Validates events that verify the user’s answer to a custom challenge.

Key changes include:
Implemented the new schemas in packages/parser/src/schemas/cognito.ts using Zod.
Updated packages/parser/src/schemas/index.ts to export all new Cognito trigger schemas.
Added and updated unit tests in packages/parser/tests/unit/schemas/cognito.test.ts to cover valid and invalid event payloads using the Prepare/Act/Assess format.
Ensured 100% test coverage for the new schemas.
Resolved Node.js import issues in index files to meet repository linting standards.
Issue number: #3675

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added parser This item relates to the Parser Utility tests PRs that add or change tests labels Mar 17, 2025
@pull-request-size pull-request-size bot added the size/M PR between 30-99 LOC label Mar 17, 2025
@dreamorosi
Copy link
Contributor

Hi @VatsalGoel3 - thank you for the PR.

I think we didn't do a good job at explaining the requirements for the issue and as a result this PR needs considerably more work.

I have left a new comment in the linked issue (here) please take a look and let me know if you have any questions.

We need to incorporate everything from that comment before we can merge this PR.

@dreamorosi dreamorosi marked this pull request as draft March 17, 2025 16:44
@dreamorosi dreamorosi linked an issue Mar 17, 2025 that may be closed by this pull request
2 tasks
@pull-request-size pull-request-size bot added size/XXL PRs with 1K+ LOC, largely documentation related and removed size/M PR between 30-99 LOC labels Mar 18, 2025
@boring-cyborg boring-cyborg bot added the dependencies Changes that touch dependencies, e.g. Dependabot, etc. label Mar 18, 2025
@VatsalGoel3
Copy link
Contributor Author

VatsalGoel3 commented Mar 18, 2025

@dreamorosi, I have added the 12 schemas as you mentioned, I had a query for the Challenge Result Schema, currently I have just defined it as an empty object and in tests for DefineAuth and CreateAuth schemas i have defined the Challenge Schema as I understand it would look like, let me know what updates would it require if any. Also after this comment, I will update the PR message to explain more in detail the feature.

@VatsalGoel3 VatsalGoel3 marked this pull request as ready for review March 18, 2025 08:47
@dreamorosi
Copy link
Contributor

Hi thanks for the PR - I'll try to review it tomorrow.

@dreamorosi
Copy link
Contributor

Hey @VatsalGoel3 - sorry for the delays on this PR.

I've been busy with the 2.17.0 release, which includes your work on the Validation utility and I haven't been able to get to this one.

I have blocked some time on Thursday (2hrs) to deploy a Cognito User Pool and test the schemas there. After that I'll provide a review, thanks for your patience.

@VatsalGoel3
Copy link
Contributor Author

@dreamorosi Hey, no worries, hope you got some time to check it out yesterday, also I would love to contribute more, maybe in testing and further task if that is something I can help with, would love to understand the end to end workflow.

@dreamorosi dreamorosi self-requested a review March 31, 2025 15:24
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @VatsalGoel3, thank you for your patience.

It took me a while to setup Cognito but I was finally able to trigger at least half of the events to verify the schemas.

I have left comments on the schemas that I manually tested and I expect to have more comments as soon as I manage to test more. You can either address them now or wait until I have posted all of them - up to you.

Besides what I left in the comments, please also:

  • add these fields to all schemas
  • move the test events in this folder and load them in their respective tests the same way that other tests for this package do
  • update the doc strings of each schema as you address the comments.

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Apr 1, 2025
@dreamorosi dreamorosi requested review from dreamorosi April 1, 2025 15:49
dreamorosi
dreamorosi previously approved these changes Apr 1, 2025
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worked on the PR and addressed all the comments + reworked the schemas & tests.

@leandrodamascena / @am29d I need a review from either of you two since I am the last committer.

VatsalGoel3 and others added 6 commits April 1, 2025 17:53
- Implemented 12 new Zod schemas for Cognito Lambda triggers:
  - Pre-Signup, Post-Confirmation, Pre-Authentication, Post-Authentication
  - Pre-Token Generation (V1 & V2), Migrate User
  - Custom Message, Custom Email Sender, Custom SMS Sender
  - Define Auth Challenge, Create Auth Challenge, Verify Auth Challenge
- Updated schemas/index.ts for dedicated exports
- Added unit tests in cognito.test.ts following Prepare/Act/Assess format
@dreamorosi dreamorosi force-pushed the feature/cognito-trigger-schema branch from e2dd5ff to b26b153 Compare April 1, 2025 15:54
Copy link

sonarqubecloud bot commented Apr 1, 2025

@dreamorosi
Copy link
Contributor

CI is failing due to this npm/cli#8203

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dreamorosi, this PR looks good to me! I created a user pool + Lambda to validate all events and I can compare it with the models here and it looks good.

In Python, I'll test each event with a specific JSON file instead of mutating base.json all the time.

Approved.

@dreamorosi dreamorosi merged commit 4116f65 into aws-powertools:main Apr 2, 2025
41 checks passed
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Apr 2, 2025
Copy link
Contributor

github-actions bot commented Apr 2, 2025

@aws-powertools/lambda-typescript No related issues found. Please ensure 'pending-release' label is applied before releasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Changes that touch dependencies, e.g. Dependabot, etc. documentation Improvements or additions to documentation feature PRs that introduce new features or minor changes parser This item relates to the Parser Utility size/XXL PRs with 1K+ LOC, largely documentation related tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add Cognito trigger schemas
3 participants