From 5e3a8aa9edf4a31c1146eec2cd762e5ab4c6a410 Mon Sep 17 00:00:00 2001 From: Jonatan Witoszek Date: Mon, 10 Feb 2025 12:41:23 +0100 Subject: [PATCH 1/3] Add missing changeset --- .changeset/silent-walls-heal.md | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .changeset/silent-walls-heal.md diff --git a/.changeset/silent-walls-heal.md b/.changeset/silent-walls-heal.md new file mode 100644 index 00000000..a7d71fa2 --- /dev/null +++ b/.changeset/silent-walls-heal.md @@ -0,0 +1,92 @@ +--- +"@saleor/app-sdk": major +--- + +`createManifestHandler` will now require `saleor-schema-version` header, sent by Saleor when fetching manifest. +`schemaVersion` parameter passed to factory method will be always defined + +### Previously: + +``` +const handler = createManifestHandler({ + manifestFactory({ schemaVersion }) { + schemaVersion -> null or number + return { + // ... + } + } +}) +``` + +Example request: + +``` +GET /api/manifest +host: my-app.com +``` + +``` +GET /api/manifest +host: my-app.com +saleor-schema-version: 3.20 +``` + +Example response: + +``` +Content-Type: application/json + +{ + "name": "Example Saleor App" + ... +} +``` + +### Now: + +``` +const handler = createManifestHandler({ + manifestFactory({ schemaVersion }) { + schemaVersion -> number + return { + // ... + } + } +}) +``` + +### Invalid request + +```http +GET /api/manifest +host: my-app.com +``` + +Response: + +``` +HTTP 400 +Content-Type: text/plain + +Missing schema version header +``` + +### Valid request + +```http +GET /api/manifest +host: my-app.com +saleor-schema-version: 3.20 +``` + +Response: + +``` +HTTP 200 +Content-Type: application/json + +{ + "name": "Example Saleor App" + ... +} +``` From 845611c6203ead3c4bd91becf27e9b21a0d5e205 Mon Sep 17 00:00:00 2001 From: Jonatan Witoszek Date: Mon, 10 Feb 2025 14:49:52 +0100 Subject: [PATCH 2/3] Update changesets description, change scope --- .changeset/hip-queens-roll.md | 2 +- .changeset/kind-zoos-raise.md | 4 ++-- .changeset/rare-tools-change.md | 34 +++++++++++++++++++++++++++++++ .changeset/serious-lamps-rhyme.md | 2 ++ .changeset/sixty-taxis-glow.md | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.changeset/hip-queens-roll.md b/.changeset/hip-queens-roll.md index 28d22aa3..87eebd74 100644 --- a/.changeset/hip-queens-roll.md +++ b/.changeset/hip-queens-roll.md @@ -1,5 +1,5 @@ --- -"@saleor/app-sdk": patch +"@saleor/app-sdk": major --- Removed `/middlewares`, you should use `/handlers` instead. diff --git a/.changeset/kind-zoos-raise.md b/.changeset/kind-zoos-raise.md index 09fa1e09..6e0f67b1 100644 --- a/.changeset/kind-zoos-raise.md +++ b/.changeset/kind-zoos-raise.md @@ -4,6 +4,6 @@ Removed deprecated fields fields and methods in `/handlers`: -- `SaleorAsyncWebhook` and `SaleorSyncWebhook` - removed `asyncEvent` and `subscriptionQueryAst` -- Removed `processSaleorWebhook` and `processProtectedHandler` methods +- `SaleorAsyncWebhook` and `SaleorSyncWebhook` - removed deprecated `asyncEvent` and `subscriptionQueryAst` +- Removed `processSaleorWebhook` and `processProtectedHandler` methods in favor of `SaleorSyncWebhook`, `SaleorAsyncWebhook` classes and `createProtectedHandler` handler - Some types were moved from `/next` to `/shared` diff --git a/.changeset/rare-tools-change.md b/.changeset/rare-tools-change.md index d07d1c18..a4ed89ea 100644 --- a/.changeset/rare-tools-change.md +++ b/.changeset/rare-tools-change.md @@ -3,3 +3,37 @@ --- Added handlers for Web API: Request and Response + +## Example + +This example uses Next.js app router + +```ts +/* /app/api/manifest/route.ts */ +export const GET = createManifestHandler({ + manifestFactory({ appBaseUrl, request }) { + return { + name: "Saleor App Template", + tokenTargetUrl: `${appBaseUrl}/api/register`, + appUrl: appBaseUrl, + permissions: ["MANAGE_ORDERS"], + id: "saleor.app", + version: "0.0.1", + webhooks: [orderCreatedWebhook.getWebhookManifest(apiBaseURL)], + author: "Saleor Commerce", + }; + }, +}); + +/* /app/api/register/route.ts */ +export const POST = createAppRegisterHandler({ + apl: saleorApp.apl, +}); +``` + +To see more details check these examples: + +- [Hono on Deno Deploy](https://github.com/witoszekdev/saleor-app-hono-deno-template) +- [Hono on Cloudflare Pages](https://github.com/witoszekdev/saleor-app-hono-cf-pages-template) +- [Hono on AWS Lambda](https://github.com/witoszekdev/saleor-app-hono-aws-lambda-template) +- [Next.js Edge Runtime](https://github.com/saleor/saleor-app-template/pull/267) diff --git a/.changeset/serious-lamps-rhyme.md b/.changeset/serious-lamps-rhyme.md index d967a1d3..de19adfe 100644 --- a/.changeset/serious-lamps-rhyme.md +++ b/.changeset/serious-lamps-rhyme.md @@ -3,3 +3,5 @@ --- Added AWS Lambda platform handlers + +Check [this example on how to use it](https://github.com/witoszekdev/saleor-app-lambda-template). diff --git a/.changeset/sixty-taxis-glow.md b/.changeset/sixty-taxis-glow.md index 0bcc9431..5b1fe5ce 100644 --- a/.changeset/sixty-taxis-glow.md +++ b/.changeset/sixty-taxis-glow.md @@ -1,5 +1,5 @@ --- -"@saleor/app-sdk": patch +"@saleor/app-sdk": minor --- Added abstract `PlatformAdapterInterface` and `ActionHandlerInterface` to enable cross-framework handler implementations. From 685a68501f03c7bb98f7d671b6e37fad63933dce Mon Sep 17 00:00:00 2001 From: Jonatan Witoszek Date: Tue, 11 Feb 2025 13:23:01 +0100 Subject: [PATCH 3/3] CR: Update examples --- .changeset/rare-tools-change.md | 8 ++++++++ .changeset/silent-walls-heal.md | 14 +++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.changeset/rare-tools-change.md b/.changeset/rare-tools-change.md index a4ed89ea..2dd56931 100644 --- a/.changeset/rare-tools-change.md +++ b/.changeset/rare-tools-change.md @@ -10,6 +10,10 @@ This example uses Next.js app router ```ts /* /app/api/manifest/route.ts */ +import { createManifestHandler } from "@saleor/app-sdk/handlers/fetch-api"; +// or +import { createManifestHandler } from "@saleor/app-sdk/handlers/next-app-router"; + export const GET = createManifestHandler({ manifestFactory({ appBaseUrl, request }) { return { @@ -24,8 +28,12 @@ export const GET = createManifestHandler({ }; }, }); +``` +```ts /* /app/api/register/route.ts */ +import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/fetch-api"; + export const POST = createAppRegisterHandler({ apl: saleorApp.apl, }); diff --git a/.changeset/silent-walls-heal.md b/.changeset/silent-walls-heal.md index a7d71fa2..c23fcfac 100644 --- a/.changeset/silent-walls-heal.md +++ b/.changeset/silent-walls-heal.md @@ -7,7 +7,7 @@ ### Previously: -``` +```ts const handler = createManifestHandler({ manifestFactory({ schemaVersion }) { schemaVersion -> null or number @@ -20,12 +20,12 @@ const handler = createManifestHandler({ Example request: -``` +```http GET /api/manifest host: my-app.com ``` -``` +```http GET /api/manifest host: my-app.com saleor-schema-version: 3.20 @@ -33,7 +33,7 @@ saleor-schema-version: 3.20 Example response: -``` +```http Content-Type: application/json { @@ -44,7 +44,7 @@ Content-Type: application/json ### Now: -``` +```ts const handler = createManifestHandler({ manifestFactory({ schemaVersion }) { schemaVersion -> number @@ -64,7 +64,7 @@ host: my-app.com Response: -``` +```http HTTP 400 Content-Type: text/plain @@ -81,7 +81,7 @@ saleor-schema-version: 3.20 Response: -``` +```http HTTP 200 Content-Type: application/json