Skip to content

Implement a direct notify API endpoint#12529

Open
rikukissa wants to merge 5 commits into
developfrom
direct-notify-endpoint
Open

Implement a direct notify API endpoint#12529
rikukissa wants to merge 5 commits into
developfrom
direct-notify-endpoint

Conversation

@rikukissa
Copy link
Copy Markdown
Member

This was requested by IET and @euanmillar as in many integration platforms like DHIS2, OpenFn etc. making a sequential request for create + notify is significantly more complex than making a singular request

This was requested by IET and @euanmillar as in many integration platforms like DHIS2, OpenFn etc. making a sequential request for create + notify is significantly more complex than making a singular request
@rikukissa rikukissa changed the base branch from develop to release-v2.0.0 May 6, 2026 06:40
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

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?".

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

ℹ️ Coverage metrics explained:
Statements — Executed code statements (basic logic lines)
Branches — Tested decision paths (if/else, switch, ternaries)
Functions — Functions invoked during tests
Lines — Source lines executed

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

📊 commons test coverage

Statements: 75.48%
Branches:   39.88%
Functions:  56.85%
Lines:      75.05%
Updated at: Thu, 07 May 2026 10:51:36 GMT

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

📊 events test coverage

Statements: 87.14%
Branches:   85%
Functions:  92.1%
Lines:      87.14%
Updated at: Thu, 07 May 2026 11:00:51 GMT

Comment on lines +109 to +123
const eventConfigs = await getInMemoryEventConfigurations(token)
const tokenScopes = getScopes(token)

const eventConfig = eventConfigs.find((c) => c.id === eventType)
if (!eventConfig) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: `No configuration found for event type: ${eventType}`
})
}

// Must have record.create scope for this event type
if (!canUserCreateEvent(tokenScopes, eventType)) {
throw new TRPCError({ code: 'FORBIDDEN' })
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could write a separate userCanCreateAndNotifyEvent middleware that does the same getRawInput() like userCanCreateEvent pattern but parses with CreateAndNotifyInput and checks both scopes. That would clean up the handler nicely.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Would that be just another layer of indirection though? I have some bad experiences with middlewares generally speaking 😬 Never really understood what the benefit is in comparison to doing something like

await userCanCreateAndNotifyEvent(user, event)

as the first step of the handler 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A plain function call might be the better fit for this case. The suggestion I made about extracting a middleware was based on the existing pattern, but the existing pattern itself is a workaround. Given the handler already has parsed input, a direct function call could be cleaner. Should be easier to debug and easier to mainitain

Comment thread packages/events/src/router/event/actions/createAndNotify.ts Outdated
config
})

// Step 2: Idempotency guard.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Idempotency for create event is handled in createEvent 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Nil20 wouldn't that only ensure if the event exists or not?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah! No need to check for CREATE's idempotency. Just checking for NOTIFY action's idempotency is the correct behavior

declaration: declaration,
annotation,
createdAtLocation,
keepAssignment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

keepAssignment should be necessary? We aren't doing actions like declare+register, so keeping assignment shouldn't probably be here

@cibelius
Copy link
Copy Markdown
Contributor

cibelius commented May 6, 2026

Maybe we should switch target branch to develop? See discussion here: https://opencrvsworkspace.slack.com/archives/C02LU432JGK/p1778069265837559

@rikukissa rikukissa changed the base branch from release-v2.0.0 to develop May 7, 2026 10:49
@rikukissa rikukissa enabled auto-merge May 7, 2026 10:49
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.

3 participants