Skip to content

Conversation

@adamsoderstrom
Copy link
Member

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2024

🦋 Changeset detected

Latest commit: 1c87da3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@noaignite/centra-types Minor
@noaignite/next-centra-checkout Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 28, 2024

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Comment Oct 2, 2025 7:21am

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds initial support for handling Centra webhook events in Next.js applications by introducing the createGetCentraWebhookEvents function and related utilities.

  • Implements webhook event parsing with signature validation for security
  • Provides adapters for both Next.js App Router and Pages Router
  • Adds comprehensive type definitions for webhook events and error handling

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/next-centra-checkout/src/createGetCentraWebhookEvents.ts Core implementation of webhook event parser with signature validation and router adapters
packages/next-centra-checkout/src/createGetCentraWebhookEvents.test.ts Comprehensive test suite covering all validation scenarios and adapter functionality
packages/centra-types/src/models/Events.ts Type definitions for Centra webhook events
packages/next-centra-checkout/package.json Package configuration and dependencies for the new library
packages/next-centra-checkout/tsup.config.ts Build configuration for TypeScript compilation
packages/next-centra-checkout/tsconfig.json TypeScript compiler configuration
packages/next-centra-checkout/src/index.ts Package exports
packages/next-centra-checkout/eslint.config.js ESLint configuration
packages/centra-types/src/models/index.ts Export addition for Events type
.changeset/shiny-kangaroos-dress.md Changeset for next-centra-checkout package
.changeset/curvy-wombats-itch.md Changeset for centra-types package
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +193 to +217
export const nextAppRouterAdapter = {
getHeader: (request, headerKey) => {
return request.headers.get(headerKey)
},
getRawBody: async (request) => {
const formData = await request.formData()

// Returning an object representation of `FormData`
return Object.fromEntries([...formData.entries()])
},
} satisfies CreateGetCentraWebhookEventsConfig<Request>['adapter']
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

The adapter functions lack proper type annotations for their parameters. Consider adding explicit types: getHeader: (request: Request, headerKey: string) => {...} and getRawBody: async (request: Request) => {...} for better type safety and IDE support.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

I do enjoy the satisfies expression more.

Comment on lines 208 to 238
export const nextPagesRouterAdapter = {
isRequestMethodPost: (request) => {
return request.method === 'POST'
},
getHeader: (request, headerKey) => {
const header = request.headers[headerKey]

if (Array.isArray(header)) {
throw new Error('Multiple headers with same key passed.')
}

return header
},
getRawBody: (req) => {
return req.body as unknown
},
} satisfies CreateGetCentraWebhookEventsConfig<NextApiRequest>['adapter']
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

The adapter functions lack proper type annotations for their parameters. Consider adding explicit types: isRequestMethodPost: (request: NextApiRequest) => boolean, getHeader: (request: NextApiRequest, headerKey: string) => {...}, and getRawBody: (req: NextApiRequest) => {...} for better type safety and IDE support.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

I do enjoy the satisfies expression more.

@adamsoderstrom adamsoderstrom force-pushed the feature/create-get-centra-webhook-events branch from a64f348 to a81618d Compare September 24, 2025 17:48
Copilot AI review requested due to automatic review settings September 24, 2025 17:50
@adamsoderstrom adamsoderstrom force-pushed the feature/create-get-centra-webhook-events branch from a81618d to c9a892d Compare September 24, 2025 17:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

sign(secret, `${parameters.t}.payload=${encodeURIComponent(body.payload)}`) !==
parameters.v1
) {
console.error('Invalid signature')
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

The console.error call should be removed or made configurable. Logging to console directly in a library function can interfere with application logging strategies and may not be appropriate for all environments.

Copilot uses AI. Check for mistakes.
}
}

const payloadParsed = JSON.parse(body.payload) as unknown
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

JSON.parse can throw a SyntaxError if the payload is not valid JSON. This should be wrapped in a try-catch block and return an appropriate error response if parsing fails.

Suggested change
const payloadParsed = JSON.parse(body.payload) as unknown
let payloadParsed: unknown
try {
payloadParsed = JSON.parse(body.payload)
} catch (err) {
return [
{
message: 'Invalid payload JSON',
},
] satisfies CentraWebhookEventsError
}

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 89.24731% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...entra-checkout/src/createGetCentraWebhookEvents.ts 90.21% 9 Missing ⚠️
packages/next-centra-checkout/src/index.ts 0.00% 0 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##             main     #319      +/-   ##
==========================================
+ Coverage   73.81%   74.46%   +0.65%     
==========================================
  Files          62       64       +2     
  Lines        2112     2205      +93     
  Branches      295      320      +25     
==========================================
+ Hits         1559     1642      +83     
- Misses        541      550       +9     
- Partials       12       13       +1     
Files with missing lines Coverage Δ
packages/next-centra-checkout/src/index.ts 0.00% <0.00%> (ø)
...entra-checkout/src/createGetCentraWebhookEvents.ts 90.21% <90.21%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adamsoderstrom adamsoderstrom force-pushed the feature/create-get-centra-webhook-events branch from c9a892d to 068abe7 Compare September 24, 2025 18:12
@adamsoderstrom adamsoderstrom force-pushed the feature/create-get-centra-webhook-events branch from 068abe7 to db0f6fc Compare September 24, 2025 18:25
Copilot AI review requested due to automatic review settings September 24, 2025 18:25
@adamsoderstrom adamsoderstrom force-pushed the feature/create-get-centra-webhook-events branch from db0f6fc to a340428 Compare September 24, 2025 18:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

parameters.v1
) {
console.error('Invalid signature')

Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider making the error logging configurable or removing it entirely. Console.error calls in library code can clutter application logs and should ideally be handled by the consuming application.

Copilot uses AI. Check for mistakes.
return [undefined, payloadParsed] as CentraWebhookEventsData
} catch (e) {
console.error(e)

Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider making the error logging configurable or removing it entirely. Console.error calls in library code can clutter application logs and should ideally be handled by the consuming application.

Copilot uses AI. Check for mistakes.
return acc
}

return { ...acc, [key]: value }
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

Using object spread operator in reduce creates a new object on each iteration. Consider using a more efficient approach like acc[key] = value; return acc to avoid unnecessary object creation.

Suggested change
return { ...acc, [key]: value }
acc[key] = value
return acc

Copilot uses AI. Check for mistakes.
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