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..2dd56931 100644 --- a/.changeset/rare-tools-change.md +++ b/.changeset/rare-tools-change.md @@ -3,3 +3,45 @@ --- Added handlers for Web API: Request and Response + +## Example + +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 { + 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", + }; + }, +}); +``` + +```ts +/* /app/api/register/route.ts */ +import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/fetch-api"; + +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/silent-walls-heal.md b/.changeset/silent-walls-heal.md new file mode 100644 index 00000000..c23fcfac --- /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: + +```ts +const handler = createManifestHandler({ + manifestFactory({ schemaVersion }) { + schemaVersion -> null or number + return { + // ... + } + } +}) +``` + +Example request: + +```http +GET /api/manifest +host: my-app.com +``` + +```http +GET /api/manifest +host: my-app.com +saleor-schema-version: 3.20 +``` + +Example response: + +```http +Content-Type: application/json + +{ + "name": "Example Saleor App" + ... +} +``` + +### Now: + +```ts +const handler = createManifestHandler({ + manifestFactory({ schemaVersion }) { + schemaVersion -> number + return { + // ... + } + } +}) +``` + +### Invalid request + +```http +GET /api/manifest +host: my-app.com +``` + +Response: + +```http +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 +HTTP 200 +Content-Type: application/json + +{ + "name": "Example Saleor App" + ... +} +``` 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.