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(api): Self Service Portal APIs #8286

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

tharakadadigama20
Copy link
Collaborator

@tharakadadigama20 tharakadadigama20 commented Jan 6, 2025

Added webhooks when registration is approved/ rejected and record search API to return records of all statuses

Ticket no: 2268 (sub task)
When an registration is approved or rejected (on correction as well), an webhook is being sent which consists of the trackingId and Status.
Sample webhook payload:

{
  "timestamp": "2025-01-08T05:36:26.790Z",
  "id": "7c473b3d-bd8e-4a54-8a9c-8644f7a205a8",
  "event": {
    "hub": {
      "topic": "BIRTH/validated"
    },
    "context": {
      "trackingId": "B0LCLL4",
      "status": "validated"
    }
  }
}

Additionally in the record search API, the declare, validated and rejected statuses registrations are also returned.

Copy link

github-actions bot commented Jan 6, 2025

Oops! Looks like you forgot to update the changelog. When updating CHANGELOG.md, please consider the following:

  • Changelog is read by country implementors who might not always be familiar with all technical details of OpenCRVS. Keep language high-level, user friendly and avoid technical references to internals.
  • Answer "What's new?", "Why was the change made?" and "Why should I care?" for each change.
  • If it's a breaking change, include a migration guide answering "What do I need to do to upgrade?".

Comment on lines 242 to 252
if (eventType === 'BIRTH' && statusType === 'approved') {
currentTrigger = TRIGGERS.BIRTH_APPROVED
} else if (eventType === 'BIRTH' && statusType === 'rejected') {
currentTrigger = TRIGGERS.BIRTH_REJECTED
} else if (eventType === 'DEATH' && statusType === 'approved') {
currentTrigger = TRIGGERS.DEATH_APPROVED
} else if (eventType === 'DEATH' && statusType === 'rejected') {
currentTrigger = TRIGGERS.DEATH_REJECTED
} else {
throw new Error('Invalid eventType or statusType')
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this filtering needed? We're making it possible for event type to be whatever value in the future so if these variables could be whatever, we'd support the new approach right away

Copy link
Member

Choose a reason for hiding this comment

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

If you want to keep this filtering, then do it on the route definition level, so instead of one catch-all

'/events/{eventType}/status/{statusType}'

you would do

/events/birth/status/approved'
/events/birth/status/rejected'

and so on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we can remove this. However, what will serve as the trigger point for the webhook?
Currently, it's set up like BIRTH_REGISTERED, DEATH_REGISTERED and so on.
How can we filter the webhook to ensure it only triggers for the desired events?

Copy link
Member

@rikukissa rikukissa Jan 8, 2025

Choose a reason for hiding this comment

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

Is there a specific constraint that prevents us from calling /events/{eventType}/status/{statusType} with arbitrary event type and status type e.g. '/events/divorce/status/my-custom-status'? The hub.topic that gets sent could directly be divorce/my-custom-status in this case without us needing the hard coded triggers at all

export enum TRIGGERS {
  BIRTH_REGISTERED,
  DEATH_REGISTERED,
  BIRTH_CERTIFIED,
  DEATH_CERTIFIED,
  BIRTH_CORRECTED,
  DEATH_CORRECTED
}

This approach would support Events v2 right away.

cc @euanmillar

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will try this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rikukissa @euanmillar
When doing this, the webhook subscribe POST API also needs to be changed.
Currently, the hub.topic should be in TRIGGERS
I have removed that validation in this API also.
Changes are pushed.

packages/webhooks/src/features/event/handler.ts Outdated Show resolved Hide resolved
packages/webhooks/src/features/event/handler.ts Outdated Show resolved Hide resolved
packages/webhooks/src/features/event/handler.ts Outdated Show resolved Hide resolved
packages/workflow/src/records/handler/correction/reject.ts Outdated Show resolved Hide resolved
packages/workflow/src/records/handler/reject.ts Outdated Show resolved Hide resolved
@@ -148,6 +149,14 @@ export const approveCorrectionRoute = createRoute({
}
)

await invokeWebhooks({
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tharakadadigama20 this webhook for correction isnt dispatching for me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have updated it. Please check now.

@euanmillar
Copy link
Collaborator

@rikukissa no sure how best to brief on how the triggers should work for Events V2. If you have any time to technically design that then I can brief the team.

@tharakadadigama20 I am not getting any webhook dispatch where a Registration Agent has validated a declaration from a field agent. This is where we would expect that BIRTH_VALIDATED webhook to be invoked. The reject one is working well. Additionally I am not getting any BIRTH_CORRECTED webhook. Maybe you should take a look through the workflow microservice some more to debug where those webhooks should be invoked.

@euanmillar euanmillar changed the title feat(api): Added webhooks when registration is approved/ rejected and record search API to return records of all statuses feat(api): Self Service Portal APIs Jan 8, 2025
@euanmillar euanmillar mentioned this pull request Jan 9, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants