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

Add support for RedisAPL & fix Docker setup #65

Open
wants to merge 5 commits into
base: canary
Choose a base branch
from

Conversation

peelar
Copy link
Member

@peelar peelar commented Jul 31, 2024

… failure urls support, support for app base path

… failure urls support, support for app base path
@peelar peelar requested a review from a team as a code owner July 31, 2024 11:39
@CLAassistant
Copy link

CLAassistant commented Jul 31, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ peelar
❌ João Ferreira


João Ferreira seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

next.config.mjs Outdated
@@ -15,11 +15,13 @@ import { withSentryConfig } from "@sentry/nextjs";
/** @type {import('next').NextConfig} */
const config = {
reactStrictMode: true,
output: "standalone",
Copy link
Member Author

Choose a reason for hiding this comment

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

question: is that needed for the dockerfile?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it is.

@@ -43,7 +44,7 @@ export const trpcClient = createTRPCNext<AppRouter>({
},
}),
httpBatchLink({
url: "/api/trpc",
url: `${env.NEXT_PUBLIC_BASE_PATH}/api/trpc`,
Copy link
Member Author

Choose a reason for hiding this comment

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

question: Won't this break if env.NEXT_PUBLIC_BASE_PATH is not provided? It can be undefined AFAIK

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, is true. The app should not start if those variables are not set.


const server = new ApolloServer({ typeDefs, resolvers });

export default startServerAndCreateNextHandler(server, {
Copy link
Member Author

Choose a reason for hiding this comment

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

question: Is this required for Apollo to work?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes


return {
token,
channel: "default-channel",
Copy link
Member Author

Choose a reason for hiding this comment

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

question/suggestion: I am not sure if this should be hardcoded. Where can we get it from?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The channel can be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

nice 👍

Comment on lines +20 to +29
tokenTargetUrl: `${apiBaseURL}${env.NEXT_PUBLIC_BASE_PATH}/api/register`,
appUrl: `${iframeBaseUrl}${env.NEXT_PUBLIC_BASE_PATH}`,
permissions: ["HANDLE_PAYMENTS"],
version: packageJson.version,
requiredSaleorVersion: ">=3.15.0",
homepageUrl: "https://docs.saleor.io/docs/3.x/developer/app-store/apps/klarna",
supportUrl: "https://github.com/saleor/saleor-app-payment-klarna/issues",
brand: {
logo: {
default: `${apiBaseURL}/logo.png`,
default: `${apiBaseURL}${env.NEXT_PUBLIC_BASE_PATH}/logo.png`,
Copy link
Member Author

Choose a reason for hiding this comment

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

question: Similar to above. Will this not break without the NEXT_PUBLIC_BASE_PATH?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, is true. The app should not start if those variables are not set.

Copy link
Member Author

Choose a reason for hiding this comment

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

question: Would it be okay for you if we moved it to App-SDK? Not blocking for this PR but in the future

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm okay with it

@peelar peelar changed the title redis support for APL; health check endpoint; cancel, back, error and… Add support for RedisAPL & fix Docker setup Aug 7, 2024
18
Copy link
Member

Choose a reason for hiding this comment

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

Why change to 18 and stay with 20 in the docker? 20 is latest LTS which is most likely a better choice unless theres issue with dependency

@@ -21,7 +22,7 @@ export const paymentGatewayInitializeSessionSyncWebhook =
apl: saleorApp.apl,
event: "PAYMENT_GATEWAY_INITIALIZE_SESSION",
query: UntypedPaymentGatewayInitializeSessionDocument,
webhookPath: "/api/webhooks/saleor/payment-gateway-initialize-session",
webhookPath: `${env.NEXT_PUBLIC_BASE_PATH}/api/webhooks/saleor/payment-gateway-initialize-session`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
webhookPath: `${env.NEXT_PUBLIC_BASE_PATH}/api/webhooks/saleor/payment-gateway-initialize-session`,
webhookPath: `/api/webhooks/saleor/payment-gateway-initialize-session`,

Urls in the webhook definitions should not be changed. The full URL is constructed in the createManifestHandler (https://github.com/saleor/saleor-app-payment-klarna/pull/65/files#diff-8b106ce88b28921d34154dd6adf1dca085721efccd424f05bc739b52c5bf72baR33). In manifest file comment provided a better solution.

@@ -17,16 +17,16 @@ export default createManifestHandler({
id: "app.saleor.klarna",
name: "Klarna",
about: packageJson.description,
tokenTargetUrl: `${apiBaseURL}/api/register`,
appUrl: iframeBaseUrl,
tokenTargetUrl: `${apiBaseURL}${env.NEXT_PUBLIC_BASE_PATH}/api/register`,
Copy link
Member

Choose a reason for hiding this comment

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

If the APP_API_BASE_URL url will be set, or appBaseURl will be passed by manifestFactory, this URL will be broken.

The best solution would be setting up APP_API_BASE_URL in the env.mjs file to use NEXT_PUBLIC_BASE_PATH.

tokenTargetUrl: `${apiBaseURL}/api/register`,
appUrl: iframeBaseUrl,
tokenTargetUrl: `${apiBaseURL}${env.NEXT_PUBLIC_BASE_PATH}/api/register`,
appUrl: `${iframeBaseUrl}${env.NEXT_PUBLIC_BASE_PATH}`,
Copy link
Member

Choose a reason for hiding this comment

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

Should be reverted


export const getAuthData = async () => {
const { apl } = saleorApp;
// ! env.SALEOR_API_URL is not required but it is type casted here
Copy link
Member

Choose a reason for hiding this comment

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

So if wont be provided, the app will fail silently.

SALEOR_API_URL should be then mandatory, or the code using this function should handle error.


try {
const token = "";
const client = createServerClient(env.SALEOR_API_URL as string, token);
Copy link
Member

Choose a reason for hiding this comment

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

Whats the purpose of adding Apollo Server to this repository? If I'm understanding it correctly, so far its only used to create gql client, and for that you can use urql which is already part of the repo (src/lib/create-graphq-client.ts)


export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const query = gql`
query test {
Copy link
Member

Choose a reason for hiding this comment

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

Would use here more meaningful name which would help recognize the source, eg

Suggested change
query test {
query KlarnaHealthCheck {

Or you can use app query, which will also return information if the app token is still valid.

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