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

Improved exported paths, added NextAppRouter specific platform #418

Merged
merged 9 commits into from
Mar 6, 2025

Conversation

lkostrowski
Copy link
Member

@lkostrowski lkostrowski commented Mar 4, 2025

  • add NextRequest and NextResponse generics

Copy link

changeset-bot bot commented Mar 4, 2025

🦋 Changeset detected

Latest commit: 79b58b8

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 Major

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

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 36.36364% with 112 lines in your changes missing coverage. Please review.

Project coverage is 81.66%. Comparing base (5e4eb20) to head (79b58b8).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tforms/next-app-router/create-protected-handler.ts 0.00% 24 Missing and 1 partial ⚠️
.../next-app-router/saleor-webhooks/saleor-webhook.ts 4.76% 20 Missing ⚠️
...-app-router/saleor-webhooks/saleor-sync-webhook.ts 7.69% 12 Missing ⚠️
...app-router/saleor-webhooks/saleor-async-webhook.ts 8.33% 11 Missing ⚠️
...rms/next-app-router/create-app-register-handler.ts 0.00% 9 Missing and 1 partial ⚠️
...atforms/next-app-router/create-manifest-handler.ts 9.09% 10 Missing ⚠️
src/handlers/platforms/next-app-router/index.ts 0.00% 6 Missing and 1 partial ⚠️
...lers/platforms/next-app-router/platform-adapter.ts 0.00% 6 Missing and 1 partial ⚠️
src/app-bridge/app-bridge.ts 66.66% 3 Missing ⚠️
src/util/public/browser/index.ts 0.00% 1 Missing and 1 partial ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #418      +/-   ##
==========================================
- Coverage   83.40%   81.66%   -1.74%     
==========================================
  Files          99      107       +8     
  Lines        3429     3502      +73     
  Branches      587      593       +6     
==========================================
  Hits         2860     2860              
- Misses        557      626      +69     
- Partials       12       16       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@lkostrowski lkostrowski changed the title WIP Missing exports Improved exported paths, added NextAppRouter specific platform Mar 4, 2025
@lkostrowski lkostrowski marked this pull request as ready for review March 4, 2025 14:47
@lkostrowski lkostrowski requested a review from a team as a code owner March 4, 2025 14:47
"types": "./util/public/browser/index.d.ts",
"import": "./util/public/browser/index.mjs",
"require": "./util/public/browser/index.js"
},
Copy link
Member Author

Choose a reason for hiding this comment

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

chaned exports - marked these for browser and node specific, removed some because they didn't make sense anymore

constructor(public request: Request) {}
export class WebApiAdapter<
TRequest extends Request = Request,
TResponse extends Response = Response,
Copy link
Member Author

Choose a reason for hiding this comment

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

In general:

Before: Next App Router platform was 1:1 re-exported FetchApi. But this is not correct because Next is extending it's Request to NextREquest, so it was limiting the usage (and NextResponse too)

Now: I created separated code for Next, reused WebApi where possible and injected NextRequest and NextResponse as generics

Copy link
Contributor

github-actions bot commented Mar 4, 2025

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20250304145310.

Install it with:

pnpm add @saleor/app-sdk@0.0.0-pr-20250304145310

package.json Outdated
"types": "./verify-jwt.d.ts",
"import": "./verify-jwt.mjs",
"require": "./verify-jwt.js"
"./auth/node": {
Copy link
Member

Choose a reason for hiding this comment

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

Question: do we support egde runtime as well or plan to do so?

I'm asking as if we don't plan to do this we can have auth/server instead 🤔

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 think it's better if we keep node for compatibility (I dont know if it works with edge) and then if we decide to support edge, we can add alias node = edge or node = server

if we do other way around and start with "server" it will require a bc

Copy link
Member Author

Choose a reason for hiding this comment

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

update: I dogfood it in Adyen and realized there is no "browser" part. JWT is from browser but it's checked on the server 🤦

So I removed node and browser and left auth

const context = validationResult.value;
try {
return await handlerFn(request, context);
} catch (err) {
Copy link
Member

Choose a reason for hiding this comment

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

Question: don't we want to log error here (even if it is in debug)?

Copy link
Contributor

github-actions bot commented Mar 4, 2025

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20250304160045.

Install it with:

pnpm add @saleor/app-sdk@0.0.0-pr-20250304160045

Copy link
Contributor

github-actions bot commented Mar 4, 2025

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20250304161552.

Install it with:

pnpm add @saleor/app-sdk@0.0.0-pr-20250304161552

Copy link
Contributor

github-actions bot commented Mar 4, 2025

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20250304162628.

Install it with:

pnpm add @saleor/app-sdk@0.0.0-pr-20250304162628

@lkostrowski lkostrowski merged commit 8dc8d4a into main Mar 6, 2025
8 checks passed
@lkostrowski lkostrowski deleted the next-app-router-handlers branch March 6, 2025 06:16
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