-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add initial version of createGetCentraWebhookEvents
#319
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 1c87da3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
c21121a to
5c7f9d7
Compare
5c7f9d7 to
0c4ec16
Compare
0c4ec16 to
863ab63
Compare
863ab63 to
03f2d5d
Compare
03f2d5d to
ebefd03
Compare
packages/react-centra-checkout/src/server/createGetCentraWebhookEvents.ts
Outdated
Show resolved
Hide resolved
packages/react-centra-checkout/src/server/createGetCentraWebhookEvents.ts
Outdated
Show resolved
Hide resolved
packages/react-centra-checkout/src/server/createGetCentraWebhookEvents.ts
Outdated
Show resolved
Hide resolved
packages/react-centra-checkout/src/server/createGetCentraWebhookEvents.ts
Outdated
Show resolved
Hide resolved
packages/react-centra-checkout/src/server/createGetCentraWebhookEvents.ts
Outdated
Show resolved
Hide resolved
ebefd03 to
2382b52
Compare
2382b52 to
25207a4
Compare
25207a4 to
c052d71
Compare
f30d3cc to
23b1375
Compare
23b1375 to
7de2df1
Compare
7de2df1 to
b9cbe8b
Compare
b9cbe8b to
a64f348
Compare
There was a problem hiding this 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.
packages/next-centra-checkout/src/createGetCentraWebhookEvents.ts
Outdated
Show resolved
Hide resolved
| 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'] |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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'] |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
a64f348 to
a81618d
Compare
a81618d to
c9a892d
Compare
There was a problem hiding this 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') |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
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.
| } | ||
| } | ||
|
|
||
| const payloadParsed = JSON.parse(body.payload) as unknown |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
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.
| 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 | |
| } |
packages/next-centra-checkout/src/createGetCentraWebhookEvents.ts
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
@@ 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
🚀 New features to boost your workflow:
|
c9a892d to
068abe7
Compare
068abe7 to
db0f6fc
Compare
db0f6fc to
a340428
Compare
There was a problem hiding this 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') | ||
|
|
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
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.
| return [undefined, payloadParsed] as CentraWebhookEventsData | ||
| } catch (e) { | ||
| console.error(e) | ||
|
|
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
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.
| return acc | ||
| } | ||
|
|
||
| return { ...acc, [key]: value } |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
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.
| return { ...acc, [key]: value } | |
| acc[key] = value | |
| return acc |
a340428 to
1c87da3
Compare
No description provided.