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

New handlers: refactored, Web API and AWS Lambda support #380

Draft
wants to merge 59 commits into
base: main
Choose a base branch
from

Conversation

witoszekdev
Copy link
Member

@witoszekdev witoszekdev commented Jan 14, 2025

Description

This PR introduces new handlers for Fetch Web API and AWS Lambda and refactors existing code so that it can easily allow adding new platforms in the future.

After the change handlers code is splits them into 3 parts:

  1. Platform Adapter - class that is responsible of:
    • parsing received requests from specific platform format (e.g. Next.js request, Web API Request) into a common format
    • and preparing response from common format into platform specific format (e.g. Next.js response, Web API Response)
  2. Handler use cases - class that represents business logic specific to handler, has a single method that returns a result
    • e.g. register use case: readers all required headers from request, validates it, saves to apl, returns success or failure
  3. Handler factory method - function that creates a handler instance with all dependencies injected, each platform has separate folder, for example:
    • src/handlers/nextjs - For handlers that use Next.js platform adapter
    • src/handlers/fetch-api - For handlers that use Fetch API platform adapter

This way we'll be able to easily add new platforms and handlers without changing existing code.

Currently in this PR:

  • Next.js - existing implementation, shouldn't be changed
  • Web API - new implementation
  • AWS Lambda event - new implementation

Breaking changes

SaleorWebhook accepts onError and formatErrorResponse parameters callbacks, now they won't pass res object in Next.js runtime, since these methods weren't supposed to send responses

@witoszekdev witoszekdev requested review from a team and lkostrowski January 14, 2025 17:58
Copy link

changeset-bot bot commented Jan 14, 2025

🦋 Changeset detected

Latest commit: 6712040

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

This PR includes changesets to release 1 package
Name Type
@saleor/app-sdk Minor

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

@witoszekdev witoszekdev changed the base branch from main to add-edge-support January 14, 2025 17:59
@witoszekdev witoszekdev marked this pull request as draft January 14, 2025 17:59
Copy link
Contributor

Package Line Rate Branch Rate Complexity Health
src 74% 93% 0
src.APL 85% 85% 0
src.APL.saleor-cloud 75% 86% 0
src.APL.vercel-kv 54% 69% 0
src.app-bridge 88% 86% 0
src.handlers.next 93% 86% 0
src.handlers.next.saleor-webhooks 91% 78% 0
src.handlers.shared 90% 76% 0
src.middleware 98% 97% 0
src.settings-manager 96% 89% 0
src.test-utils 100% 90% 0
src.util 82% 100% 0
Summary 85% (4081 / 4775) 85% (485 / 569) 0

Copy link
Member

@lkostrowski lkostrowski left a comment

Choose a reason for hiding this comment

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

It would be easier for me to review if I already see docs with examples. In case of SDK public API is more important than the code

@@ -0,0 +1,5 @@
---
"@saleor/app-sdk": minor
Copy link
Member

Choose a reason for hiding this comment

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

please make it major since it has breaking changes

"@saleor/app-sdk": minor
---

Added `handlers/fetch-api` which adds support for frameworks that use [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
Copy link
Member

Choose a reason for hiding this comment

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

please remember to add full changeset and docs

Comment on lines +153 to +157
"./handlers/next-app-router": {
"types": "./handlers/fetch-api/index.d.ts",
"import": "./handlers/fetch-api/index.mjs",
"require": "./handlers/fetch-api/index.js"
},
Copy link
Member

Choose a reason for hiding this comment

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

won't it have the same names as fetch api? It would be confusing, probably better to also add alias on export

so next-app-router file can include export { FetchApi as NextAppRouterWebhook } from '../fetch-api' or something like this

Copy link
Member

Choose a reason for hiding this comment

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

would be easier if we see docs at this point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants