@jiggai/kitchen-plugin-marketing 0.3.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/handler.js +48 -0
- package/dist/tabs/content-calendar.js +891 -46
- package/dist/tabs/content-library.js +217 -105
- package/package.json +1 -1
package/dist/api/handler.js
CHANGED
|
@@ -954,6 +954,54 @@ async function handleRequest(req, ctx) {
|
|
|
954
954
|
return apiError(500, "DATABASE_ERROR", error?.message || "Unknown error");
|
|
955
955
|
}
|
|
956
956
|
}
|
|
957
|
+
const singlePostMatch = req.path.match(/^\/posts\/([a-f0-9-]+)$/);
|
|
958
|
+
if (singlePostMatch && req.method === "GET") {
|
|
959
|
+
try {
|
|
960
|
+
const { db } = initializeDatabase(teamId);
|
|
961
|
+
const [post] = await db.select().from(posts).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(posts.id, singlePostMatch[1]), (0, import_drizzle_orm2.eq)(posts.teamId, teamId)));
|
|
962
|
+
if (!post) return apiError(404, "NOT_FOUND", "Post not found");
|
|
963
|
+
return {
|
|
964
|
+
status: 200,
|
|
965
|
+
data: {
|
|
966
|
+
...post,
|
|
967
|
+
platforms: JSON.parse(post.platforms || "[]"),
|
|
968
|
+
tags: JSON.parse(post.tags || "[]"),
|
|
969
|
+
mediaIds: JSON.parse(post.mediaIds || "[]")
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
} catch (error) {
|
|
973
|
+
return apiError(500, "DATABASE_ERROR", error?.message || "Unknown error");
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (singlePostMatch && req.method === "DELETE") {
|
|
977
|
+
try {
|
|
978
|
+
const { db } = initializeDatabase(teamId);
|
|
979
|
+
const [post] = await db.select().from(posts).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(posts.id, singlePostMatch[1]), (0, import_drizzle_orm2.eq)(posts.teamId, teamId)));
|
|
980
|
+
if (!post) return apiError(404, "NOT_FOUND", "Post not found");
|
|
981
|
+
await db.delete(posts).where((0, import_drizzle_orm2.eq)(posts.id, singlePostMatch[1]));
|
|
982
|
+
return { status: 200, data: { deleted: true, id: singlePostMatch[1] } };
|
|
983
|
+
} catch (error) {
|
|
984
|
+
return apiError(500, "DATABASE_ERROR", error?.message || "Unknown error");
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
if (singlePostMatch && req.method === "PATCH") {
|
|
988
|
+
try {
|
|
989
|
+
const { db } = initializeDatabase(teamId);
|
|
990
|
+
const [post] = await db.select().from(posts).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(posts.id, singlePostMatch[1]), (0, import_drizzle_orm2.eq)(posts.teamId, teamId)));
|
|
991
|
+
if (!post) return apiError(404, "NOT_FOUND", "Post not found");
|
|
992
|
+
const body = req.body || {};
|
|
993
|
+
const updates = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
994
|
+
if (body.content !== void 0) updates.content = body.content;
|
|
995
|
+
if (body.platforms !== void 0) updates.platforms = JSON.stringify(body.platforms);
|
|
996
|
+
if (body.status !== void 0) updates.status = body.status;
|
|
997
|
+
if (body.scheduledAt !== void 0) updates.scheduledAt = body.scheduledAt || null;
|
|
998
|
+
if (body.tags !== void 0) updates.tags = JSON.stringify(body.tags);
|
|
999
|
+
await db.update(posts).set(updates).where((0, import_drizzle_orm2.eq)(posts.id, singlePostMatch[1]));
|
|
1000
|
+
return { status: 200, data: { updated: true, id: singlePostMatch[1] } };
|
|
1001
|
+
} catch (error) {
|
|
1002
|
+
return apiError(500, "DATABASE_ERROR", error?.message || "Unknown error");
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
957
1005
|
return apiError(501, "NOT_IMPLEMENTED", `No handler for ${req.method} ${req.path}`);
|
|
958
1006
|
}
|
|
959
1007
|
// Annotate the CommonJS export names for ESM import in node:
|