diff --git a/src/APL/saleor-cloud-apl.ts b/src/APL/saleor-cloud-apl.ts index 437deafc..a04298b0 100644 --- a/src/APL/saleor-cloud-apl.ts +++ b/src/APL/saleor-cloud-apl.ts @@ -25,6 +25,15 @@ const mapAuthDataToAPIBody = (authData: AuthData) => ({ token: authData.token, }); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const mapAPIResponseToAuthData = (response: any): AuthData => ({ + appId: response.saleor_app_id, + domain: response.domain, + jwks: response.jwks, + saleorApiUrl: response.saleor_api_url, + token: response.token, +}); + /** * * Saleor Cloud APL - handle auth data management via REST API. @@ -68,7 +77,8 @@ export class SaleorCloudAPL implements APL { debug("Failed to parse response: %s", e?.message ?? "Unknown error"); })) as unknown; - const authData = authDataFromObject(parsedResponse); + const authData = authDataFromObject(mapAPIResponseToAuthData(parsedResponse)); + if (!authData) { debug("No auth data for given saleorApiUrl"); return undefined; diff --git a/src/handlers/next/process-async-saleor-webhook.test.ts b/src/handlers/next/process-async-saleor-webhook.test.ts index 8e5ac648..4de9d80c 100644 --- a/src/handlers/next/process-async-saleor-webhook.test.ts +++ b/src/handlers/next/process-async-saleor-webhook.test.ts @@ -151,6 +151,9 @@ describe("processAsyncSaleorWebhook", () => { it("Throw error on wrong signature", async () => { mockRequest.headers["saleor-signature"] = "wrong_signature"; + vi.mock("./../../fetch-remote-jwks", () => ({ + fetchRemoteJwks: vi.fn(() => "wrong_signature"), + })); await expect( processAsyncSaleorWebhook({ req: mockRequest,