Skip to content

Commit

Permalink
add diff netlify function
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanKiral committed Oct 8, 2024
1 parent 23e6d22 commit b545004
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/functions/diff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// import { diffEnvironments } from "@kontent-ai/data-ops";
import { Handler } from "@netlify/functions";
import { z } from "zod";
import { fromError } from "zod-validation-error";

const diffParamsSchema = z.strictObject({
sourceEnvironmentId: z.string(),
sourceApiKey: z.string(),
targetEnvironmentId: z.string(),
targetApiKey: z.string(),
});

export const handler: Handler = async (event) => {
if (event.httpMethod !== "POST") {
return {
statusCode: 405,
body: "Method not allowed",
};
}

const contentType = event.headers["content-type"] || event.headers["Content-Type"];
if (!contentType || !contentType.includes("application/json")) {
return {
statusCode: 400,
body: "Content-Type must be application/json",
};
}

const result = diffParamsSchema.safeParse(JSON.parse(event.body ?? ""));

if (!result.success) {
return {
statusCode: 400,
body: fromError(result.error).message,
};
}

// const diffHtml = await diffEnvironments({
// sourceEnvironmentId: result.data.sourceEnvironmentId,
// sourceApiKey: result.data.sourceApiKey,
// targetEnvironmentId: result.data.targetEnvironmentId,
// targetApiKey: result.data.targetApiKey,
// });

return {
statusCode: 200,
body: "diffHtml",
};
};

0 comments on commit b545004

Please sign in to comment.