Skip to content

Commit

Permalink
Fix Next.js build errors
Browse files Browse the repository at this point in the history
witoszekdev committed Jan 10, 2025
1 parent bc4b91a commit 1064c5b
Showing 7 changed files with 94 additions and 106 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
"pnpm": ">=9.0.0 <10.0.0"
},
"dependencies": {
"@saleor/app-sdk": "0.0.0-pr-20250103130801",
"@saleor/app-sdk": "0.0.0-pr-20250109150409",
"@saleor/macaw-ui": "1.1.10",
"@urql/exchange-auth": "^1.0.0",
"@vitejs/plugin-react": "4.2.1",
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/app/api-v2/manifest/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createManifestHandler } from "@saleor/app-sdk/handlers/fetch-api";
import { AppManifest } from "@saleor/app-sdk/types";
import packageJson from "../../../../package.json";
import { orderFilterShippingMethodsWebhook } from "../webhooks/order-filter-shipping-methods/route";
import { orderCreatedWebhook } from "../webhooks/order-created/route";
import { orderCreatedWebhook } from "../webhooks/order-created/webhook";
import { orderFilterShippingMethodsWebhook } from "../webhooks/order-filter-shipping-methods/webhook";

export const GET = createManifestHandler({
manifestFactory({ appBaseUrl, request }) {
58 changes: 1 addition & 57 deletions src/app/api-v2/webhooks/order-created/route.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
import { gql } from "urql";
import { OrderCreatedWebhookPayloadFragment } from "../../../../../generated/graphql";
import { saleorApp } from "../../../../saleor-app";
import { SaleorAsyncWebhook } from "@saleor/app-sdk/handlers/fetch-api";
import { createClient } from "../../../../lib/create-graphq-client";

/**
* Example payload of the webhook. It will be transformed with graphql-codegen to Typescript type: OrderCreatedWebhookPayloadFragment
*/
const OrderCreatedWebhookPayload = gql`
fragment OrderCreatedWebhookPayload on OrderCreated {
order {
userEmail
id
number
user {
email
firstName
lastName
}
}
}
`;

/**
* Top-level webhook subscription query, that will be attached to the Manifest.
* Saleor will use it to register webhook.
*/
const OrderCreatedGraphqlSubscription = gql`
# Payload fragment must be included in the root query
${OrderCreatedWebhookPayload}
subscription OrderCreated {
event {
...OrderCreatedWebhookPayload
}
}
`;

/**
* Create abstract Webhook. It decorates handler and performs security checks under the hood.
*
* orderCreatedWebhook.getWebhookManifest() must be called in api/manifest too!
*/
export const orderCreatedWebhook = new SaleorAsyncWebhook<OrderCreatedWebhookPayloadFragment>({
name: "Order Created in Saleor",
webhookPath: "api-v2/webhooks/order-created",
event: "ORDER_CREATED",
apl: saleorApp.apl,
query: OrderCreatedGraphqlSubscription,
});
import { orderCreatedWebhook } from "./webhook";

/**
* Export decorated Request handler, which adds extra context
@@ -95,11 +47,3 @@ export const POST = orderCreatedWebhook.createHandler((request, ctx) => {
return new Response("Accepted", { status: 200 });
});

/**
* Disable body parser for this endpoint, so signature can be verified
*/
export const config = {
api: {
bodyParser: false,
},
};
49 changes: 49 additions & 0 deletions src/app/api-v2/webhooks/order-created/webhook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { gql } from "urql";
import { OrderCreatedWebhookPayloadFragment } from "../../../../../generated/graphql";
import { saleorApp } from "../../../../saleor-app";
import { SaleorAsyncWebhook } from "@saleor/app-sdk/handlers/fetch-api";

/**
* Example payload of the webhook. It will be transformed with graphql-codegen to Typescript type: OrderCreatedWebhookPayloadFragment
*/
const OrderCreatedWebhookPayload = gql`
fragment OrderCreatedWebhookPayload on OrderCreated {
order {
userEmail
id
number
user {
email
firstName
lastName
}
}
}
`;

/**
* Top-level webhook subscription query, that will be attached to the Manifest.
* Saleor will use it to register webhook.
*/
const OrderCreatedGraphqlSubscription = gql`
# Payload fragment must be included in the root query
${OrderCreatedWebhookPayload}
subscription OrderCreated {
event {
...OrderCreatedWebhookPayload
}
}
`;

/**
* Create abstract Webhook. It decorates handler and performs security checks under the hood.
*
* orderCreatedWebhook.getWebhookManifest() must be called in api/manifest too!
*/
export const orderCreatedWebhook = new SaleorAsyncWebhook<OrderCreatedWebhookPayloadFragment>({
name: "Order Created in Saleor",
webhookPath: "api-v2/webhooks/order-created",
event: "ORDER_CREATED",
apl: saleorApp.apl,
query: OrderCreatedGraphqlSubscription,
});
42 changes: 1 addition & 41 deletions src/app/api-v2/webhooks/order-filter-shipping-methods/route.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,7 @@
import { gql } from "urql";
import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/fetch-api";
import { OrderFilterShippingMethodsPayloadFragment } from "../../../../../generated/graphql";
import { saleorApp } from "../../../../saleor-app";

const OrderFilterShippingMethodsPayload = gql`
fragment OrderFilterShippingMethodsPayload on OrderFilterShippingMethods {
order {
deliveryMethod {
... on ShippingMethod {
id
name
}
}
}
}
`;

const OrderFilterShippingMethodsSubscription = gql`
${OrderFilterShippingMethodsPayload}
subscription OrderFilterShippingMethods {
event {
...OrderFilterShippingMethodsPayload
}
}
`;

export const orderFilterShippingMethodsWebhook =
new SaleorSyncWebhook<OrderFilterShippingMethodsPayloadFragment>({
name: "Order Filter Shipping Methods",
webhookPath: "api-v2/webhooks/order-filter-shipping-methods",
event: "ORDER_FILTER_SHIPPING_METHODS",
apl: saleorApp.apl,
query: OrderFilterShippingMethodsSubscription,
});
import { orderFilterShippingMethodsWebhook } from "./webhook";

export const POST = orderFilterShippingMethodsWebhook.createHandler((request, ctx) => {
const { payload } = ctx;
console.log("Order Filter Shipping Methods Webhook received with: ", payload);
return new Response("{}", { status: 200 })
});

export const config = {
api: {
bodyParser: false,
},
};
35 changes: 35 additions & 0 deletions src/app/api-v2/webhooks/order-filter-shipping-methods/webhook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { gql } from "urql";
import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/fetch-api";
import { OrderFilterShippingMethodsPayloadFragment } from "../../../../../generated/graphql";
import { saleorApp } from "../../../../saleor-app";

const OrderFilterShippingMethodsPayload = gql`
fragment OrderFilterShippingMethodsPayload on OrderFilterShippingMethods {
order {
deliveryMethod {
... on ShippingMethod {
id
name
}
}
}
}
`;

const OrderFilterShippingMethodsSubscription = gql`
${OrderFilterShippingMethodsPayload}
subscription OrderFilterShippingMethods {
event {
...OrderFilterShippingMethodsPayload
}
}
`;

export const orderFilterShippingMethodsWebhook =
new SaleorSyncWebhook<OrderFilterShippingMethodsPayloadFragment>({
name: "Order Filter Shipping Methods",
webhookPath: "api-v2/webhooks/order-filter-shipping-methods",
event: "ORDER_FILTER_SHIPPING_METHODS",
apl: saleorApp.apl,
query: OrderFilterShippingMethodsSubscription,
});

0 comments on commit 1064c5b

Please sign in to comment.