Skip to content

Commit

Permalink
updata to data-ops 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanKiral committed Oct 22, 2024
1 parent 0b89699 commit 10c121a
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"overrides": [
{
"files": ["src/**/*.ts"],
"files": ["src/**/*.ts", "netlify/**/*.ts"],
"excludedFiles": ["src/log.ts", "vite.config.ts"]
}
],
Expand Down
1 change: 0 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[build]
command = "npm run build"
publish = "dist"
functions = "src/functions"

[[redirects]]
from = "/*"
Expand Down
41 changes: 30 additions & 11 deletions src/functions/diff.ts → netlify/functions/diff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { diffEnvironments } from "@kontent-ai/data-ops";
import { syncDiff } from "@kontent-ai/data-ops";
import { Handler } from "@netlify/functions";
import { z } from "zod";
import { fromError } from "zod-validation-error";
Expand All @@ -8,6 +8,17 @@ const diffParamsSchema = z.strictObject({
sourceApiKey: z.string(),
targetEnvironmentId: z.string(),
targetApiKey: z.string(),
entities: z.array(z.enum([
"contentTypes",
"contentTypeSnippets",
"taxonomies",
"collections",
"assetFolders",
"spaces",
"languages",
"webSpotlight",
"workflows",
])),
});

export const handler: Handler = async (event) => {
Expand Down Expand Up @@ -35,15 +46,23 @@ export const handler: Handler = async (event) => {
};
}

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

return {
statusCode: 200,
body: "diffHtml",
};
return {
statusCode: 200,
body: JSON.stringify({ html: diffHtml }),
};
} catch (e) {
return {
statusCode: 500,
body: JSON.stringify(e, Object.getOwnPropertyNames(e)),
};
}
};
9 changes: 7 additions & 2 deletions src/functions/sync.ts → netlify/functions/sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { syncModelRun } from "@kontent-ai/data-ops";
import { syncRun } from "@kontent-ai/data-ops";
import { Handler } from "@netlify/functions";
import { z } from "zod";
import { fromError } from "zod-validation-error";
Expand Down Expand Up @@ -47,7 +47,12 @@ export const handler: Handler = async (event) => {
}

try {
await syncModelRun(result.data);
await syncRun({
...result.data,
entities: Object.fromEntries(
result.data.entities.map(key => [key, key == "webSpotlight" ? true : () => true]),
),
});

return {
statusCode: 200,
Expand Down
Loading

0 comments on commit 10c121a

Please sign in to comment.